package com.zhongwang.business.module.estimateBudgetAccountingManage.service;

import java.util.Date;

import com.zhongwang.business.base.BaseService;
import com.zhongwang.business.common.ImportCallBack;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.gen.entity.*;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.AccountingDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.AccountingInfoDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.dao.GetDataDao;
import com.zhongwang.business.module.estimateBudgetAccountingManage.excelListener.*;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.*;
import com.zhongwang.business.module.estimateBudgetAccountingManage.model.excelImport.*;
import com.zhongwang.business.util.BeanUtil;
import com.zhongwang.business.util.FileUtils;
import com.zhongwang.business.util.XYHFileUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.math.BigDecimal;
import java.util.*;

/**
 * AccountingInfoService 核算清单明细页业务逻辑层
 *
 * @author 徐一贺
 * @version 1.0
 * @date 2020/10/8 9:17
 */
@Log4j2
@Service
public class AccountingInfoService extends BaseService {

    @Autowired
    private AccountingInfoDao accountingInfoDao;
    @Autowired
    private GetDataService getDataService;
    @Autowired
    private GetDataDao getDataDao;
    /**
     * 错误信息
     */
    private String msg = "";

    /**
     * 用户上传文件路径
     */
    @Value("${user.upload.path}")
    private String uploadPath;

    /**
     * getAbBudgetAccountingTaskByPrimaryKey 依据主键获取单据表信息
     *
     * @param batId 单据表主键
     * @return com.zhongwang.business.gen.entity.BusBudgetAccountingTask 返回类型
     * @author 徐一贺
     * @date 2020/10/8 9:20
     */
    public BusBudgetAccountingTask getAbBudgetAccountingTaskByPrimaryKey(Integer batId) {
        return accountingInfoDao.getAbBudgetAccountingTaskByPrimaryKey(batId);
    }

    /**
     * getBusBudgetAccountingCostByPrimaryKey 依据主键获取对应成本项
     *
     * @param id 主键
     * @return com.zhongwang.business.gen.entity.BusBudgetAccountingCost 返回类型
     * @author 徐一贺
     * @date 2020/10/8 14:16
     */
    public BusBudgetAccountingCost getBusBudgetAccountingCostByPrimaryKey(Integer id) {
        return accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(id);
    }

    /**
     * getTax 获取税率
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/8 14:42
     */
    public JsonResult getTax(BusBudgetAccountingCost param) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingBasicInfoConfig busBudgetAccountingBasicInfoConfig =
                    accountingInfoDao.getBusBudgetAccountingBasicInfoConfigByPrimaryKeyAndCode(
                            param.getBatId(), "tax");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setData(busBudgetAccountingBasicInfoConfig);
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
        }
        return jsonResult;
    }

    /**
     * rawMaterialList 获取材料列表
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/9 10:40
     */
    public List<BusMaterialData> rawMaterialList(BusMaterialData param) {
        return accountingInfoDao.findRawMaterialList(param);
    }

    /**
     * purList 获取外购件列表
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/9 10:40
     */
    public List<BusMaterialData> purList(BusMaterialData param) {
        return accountingInfoDao.findPurList(param);
    }

    /**
     * wholeOutList 获取整体外协列表
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/9 10:40
     */
    public List<BusMaterialDataModel> wholeOutList(BusMaterialDataModel param) {
        return accountingInfoDao.findWholeOutList(param);
    }

    /**
     * withMatOutList 获取带料外协列表
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/9 10:40
     */
    public List<BusMaterialDataModel> withMatOutList(BusMaterialDataModel param) {
        return accountingInfoDao.findWithMatOutList(param);
    }

    /**
     * saveEdit 保存修改
     *
     * @param param 信息等
     * @return com.zhongwang.business.common.JsonResult 结果
     * @author 徐一贺
     * @date 2020/10/9 16:35
     */
    public JsonResult saveEdit(BusMaterialDataModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingCost cost =
                    accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getCostId());
            if (cost.getCode().contains("-材料费-材料采购费-")) {
                accountingInfoDao.updateByPrimaryKeySelective(param);
            } else if (cost.getCode().contains("-制造费-")) {
                BusGeneralHoursModel data = new BusGeneralHoursModel();
                data.setId(param.getId());
                data.setLaborNum(param.getLaborNum());
                data.setPrice(param.getPrice());
                data.setPriceType(param.getPriceType());
                accountingInfoDao.updateBusGeneralHoursModelByPrimaryKeySelective(data);
            }

            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
            log.error("保存失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * saveGeneralHoursEdit 保存修改
     *
     * @param param 信息等
     * @return com.zhongwang.business.common.JsonResult 结果
     * @author 徐一贺
     * @date 2020/10/9 16:35
     */
    public JsonResult saveGeneralHoursEdit(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            accountingInfoDao.updateBusGeneralHoursModelByPrimaryKeySelective(param);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
            log.error("保存原材料单价失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * automaticCalculation 原材料自动计算
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/10 14:04
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult automaticCalculationRawMaterial(BusBudgetAccountingCostModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            // 设置该成本项的状态为已完成
            BusBudgetAccountingCost busBudgetAccountingCost =
                    accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
            // 设置被除数
            BigDecimal divisor = new BigDecimal(0);
            switch (busBudgetAccountingCost.getAmountDisplayModel().intValue()) {
                case 1:
                    divisor = new BigDecimal(1);
                    break;
                case 2:
                    divisor = new BigDecimal(10000);
                    break;
                case 3:
                    divisor = new BigDecimal(1000000);
                    break;
                default:
                    divisor = new BigDecimal(100000000);
                    break;
            }
            param.setMajor(busBudgetAccountingCost.getMajor());
            busBudgetAccountingCost.setFinishStatus(3);
            accountingInfoDao.updateBusBudgetAccountingCostFinishStatusByPrimaryKeySelective(
                    busBudgetAccountingCost);
            BusBudgetAccountingTaskModel order =
                    accountingInfoDao.getBusBudgetAccountingTaskModelById(param.getBatId());
            VwProject vwProject = accountingInfoDao.getVwProjectByCode(order.getProCode());
            // 获取税
            BusBudgetAccountingBasicInfoConfig busBudgetAccountingBasicInfoConfig =
                    accountingInfoDao.getBusBudgetAccountingBasicInfoConfigByPrimaryKeyAndCode(
                            param.getBatId(), "tax");
            BigDecimal tax = new BigDecimal(busBudgetAccountingBasicInfoConfig.getValue());
            if (busBudgetAccountingCost.getCode().contains("-碳钢")) {
                param.setTexture("碳钢");
            } else if (busBudgetAccountingCost.getCode().contains("-不锈钢")) {
                param.setTexture("不锈钢");
            } else if (busBudgetAccountingCost.getCode().contains("-铝材")) {
                param.setTexture("铝材");
            } else if (busBudgetAccountingCost.getCode().contains("-其他")) {
                param.setTexture("其他");
            }
            // 获取总金额(含税)
            BigDecimal totalAmountTax = accountingInfoDao.getRawMateriaTotalAmount(param);
            if (totalAmountTax != null) {
                // 获取总金额
                BigDecimal totalAmount = new BigDecimal(0);
                totalAmount =
                        totalAmountTax.divide(
                                new BigDecimal(1).add(
                                        tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)),8,BigDecimal.ROUND_HALF_UP);
                // 获取总料重单位吨
                BigDecimal totalNum =
                        accountingInfoDao
                                .getRawMateriaTotalNum(param)
                                .divide(new BigDecimal(1000), 8, BigDecimal.ROUND_HALF_UP);
                // 反写 料重 总价 单价 这些数据皆除以项目数量
                busBudgetAccountingCost.setNum(
                        totalNum.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                busBudgetAccountingCost.setDisplayNum(
                        totalNum
                                .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
                busBudgetAccountingCost.setTotalPrice(
                        totalAmount.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                    busBudgetAccountingCost.setDisplayTotalPrice(
                            totalAmount
                                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    busBudgetAccountingCost.setDisplayTotalPrice(
                            totalAmount
                                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                    .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
                if (totalNum.compareTo(new BigDecimal(0)) == 0) {
                    busBudgetAccountingCost.setPrice(new BigDecimal(0));
                    busBudgetAccountingCost.setDisplayPrice("0");
                } else {
                    busBudgetAccountingCost.setPrice(
                            busBudgetAccountingCost
                                    .getTotalPrice()
                                    .divide(busBudgetAccountingCost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                    if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                        busBudgetAccountingCost.setDisplayPrice(
                                busBudgetAccountingCost
                                        .getTotalPrice()
                                        .divide(busBudgetAccountingCost.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    } else {
                        busBudgetAccountingCost.setDisplayPrice(
                                busBudgetAccountingCost
                                        .getTotalPrice()
                                        .divide(busBudgetAccountingCost.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                }
                accountingInfoDao.updateBusBudgetAccountingCostByPrimaryKeySelective(
                        busBudgetAccountingCost);
                // 记录数据---重量
                BusBudgetAccountingEstimatesData accountingData = new BusBudgetAccountingEstimatesData();
                accountingData.setBatId(param.getBatId());
                accountingData.setProCode(vwProject.getCode());
                accountingData.setUseType(2);
                accountingData.setDataMajor(busBudgetAccountingCost.getMajor());
                accountingData.setDataPart(busBudgetAccountingCost.getPart());
                accountingData.setCostId(busBudgetAccountingCost.getId());
                if (busBudgetAccountingCost.getCode().contains("-碳钢")
                        || busBudgetAccountingCost.getCode().contains("-不锈钢")
                        || busBudgetAccountingCost.getCode().contains("-铝材")) {
                    if (busBudgetAccountingCost.getCode().contains("-碳钢")) {
                        accountingData.setDataType("该项目材料费碳钢总料重");
                    } else if (busBudgetAccountingCost.getCode().contains("-不锈钢")) {
                        accountingData.setDataType("该项目材料费不锈钢总料重");
                    } else if (busBudgetAccountingCost.getCode().contains("-铝材")) {
                        accountingData.setDataType("该项目材料费铝材总料重");
                    }
                    BusBudgetAccountingEstimatesData extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    if (extistsData != null) {
                        accountingData = extistsData;
                        if(totalNum.compareTo(BigDecimal.ZERO)==0){
                            accountingData.setDataValue("0.00");
                        }else{
                            accountingData.setDataValue(totalNum.toString());
                        }
                        accountingData.setDataUnit("吨");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    } else {
                        if(totalNum.compareTo(BigDecimal.ZERO)==0){
                            accountingData.setDataValue("0.00");
                        }else{
                            accountingData.setDataValue(totalNum.toString());
                        }
                        accountingData.setDataUnit("吨");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    }

                    // 获取
                }
                // 记录数据---总价
                if (busBudgetAccountingCost.getCode().contains("-碳钢")) {
                    accountingData.setDataType("该项目材料费碳钢总价");
                } else if (busBudgetAccountingCost.getCode().contains("-不锈钢")) {
                    accountingData.setDataType("该项目材料费不锈钢总价");
                } else if (busBudgetAccountingCost.getCode().contains("-铝材")) {
                    accountingData.setDataType("该项目材料费铝材总价");
                } else if (busBudgetAccountingCost.getCode().contains("-其他")) {
                    accountingData.setDataType("该项目材料费其他总价");
                }
                BusBudgetAccountingEstimatesData extistsData =
                        accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                if (extistsData != null) {
                    accountingData = extistsData;
                    if(totalAmount.compareTo(BigDecimal.ZERO)==0){
                        accountingData.setDataValue("0.00");
                    }else{
                        accountingData.setDataValue(totalAmount.toString());
                    }
                    accountingData.setDataUnit("元");
                    accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                } else {
                    if(totalAmount.compareTo(BigDecimal.ZERO)==0){
                        accountingData.setDataValue("0.00");
                    }else{
                        accountingData.setDataValue(totalAmount.toString());
                    }
                    accountingData.setDataUnit("元");
                    accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                }
                // 记录数据---单价
                if (busBudgetAccountingCost.getCode().contains("-碳钢")
                        || busBudgetAccountingCost.getCode().contains("-不锈钢")
                        || busBudgetAccountingCost.getCode().contains("-铝材")) {
                    if (busBudgetAccountingCost.getCode().contains("-碳钢")) {
                        accountingData.setDataType("该项目材料费碳钢单价");
                    } else if (busBudgetAccountingCost.getCode().contains("-不锈钢")) {
                        accountingData.setDataType("该项目材料费不锈钢单价");
                    } else if (busBudgetAccountingCost.getCode().contains("-铝材")) {
                        accountingData.setDataType("该项目材料费铝材单价");
                    }
                    extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    if (extistsData != null) {
                        accountingData = extistsData;
                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                            accountingData.setDataValue(
                                    totalAmount.divide(totalNum, 8, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            accountingData.setDataValue("0.00");
                        }
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    } else {
                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                            accountingData.setDataValue(
                                    totalAmount.divide(totalNum, 8, BigDecimal.ROUND_HALF_UP).toString());
                        } else {
                            accountingData.setDataValue("0.00");
                        }
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    }
                }
                // 设置返回体内容
                Map<String, Object> resultMap = new HashMap();
                resultMap.put("tax", tax);
                resultMap.put("totalAmount", totalAmount);
                resultMap.put("totalAmountTax", totalAmountTax);
                resultMap.put("busBudgetAccountingCost", busBudgetAccountingCost);
                jsonResult.setData(resultMap);
                jsonResult.setType(JsonResult.ResultType.SUCCESS);
                jsonResult.setMsg("计算成功！");
            } else {
                jsonResult.setType(JsonResult.ResultType.ERROR);
                jsonResult.setMsg("因部分物料无单价，所以无法核算！");
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("计算失败！");
            log.error("原材料计算失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * automaticCalculation 外购件自动计算
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/10 14:04
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult automaticCalculationPur(BusBudgetAccountingCostModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            // 设置该成本项的状态为已完成
            BusBudgetAccountingCost busBudgetAccountingCost =
                    accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
            // 设置被除数
            BigDecimal divisor = new BigDecimal(0);
            switch (busBudgetAccountingCost.getAmountDisplayModel().intValue()) {
                case 1:
                    divisor = new BigDecimal(1);
                    break;
                case 2:
                    divisor = new BigDecimal(10000);
                    break;
                case 3:
                    divisor = new BigDecimal(1000000);
                    break;
                default:
                    divisor = new BigDecimal(100000000);
                    break;
            }
            busBudgetAccountingCost.setFinishStatus(3);
            accountingInfoDao.updateBusBudgetAccountingCostFinishStatusByPrimaryKeySelective(
                    busBudgetAccountingCost);
            BusBudgetAccountingTaskModel order =
                    accountingInfoDao.getBusBudgetAccountingTaskModelById(param.getBatId());
            VwProject vwProject = accountingInfoDao.getVwProjectByCode(order.getProCode());
            // 获取税
            BusBudgetAccountingBasicInfoConfig busBudgetAccountingBasicInfoConfig =
                    accountingInfoDao.getBusBudgetAccountingBasicInfoConfigByPrimaryKeyAndCode(
                            param.getBatId(), "tax");
            BigDecimal tax = new BigDecimal(busBudgetAccountingBasicInfoConfig.getValue());
            // 设置返回体内容
            Map<String, Object> resultMap = new HashMap<>();
            resultMap.put("tax", tax);
            // 获取总金额(含税)
            BigDecimal totalAmountTax = accountingInfoDao.getPurTotalAmount(param);
            // 总金额不含税
            BigDecimal totalAmount = new BigDecimal(0);
            if (totalAmountTax != null) {
                // 获取总金额
                totalAmount =
                        totalAmountTax.divide(new BigDecimal(1).add(tax.divide(new BigDecimal(100),8,BigDecimal.ROUND_HALF_UP)),8,BigDecimal.ROUND_HALF_UP);
                //                //获取总数量
                //                BigDecimal totalNum = accountingInfoDao.getPurTotalNum(param);
                //                //反写 总数量 总价 单价 这些数据皆除以项目数量
                //                busBudgetAccountingCost.setNum(totalNum.divide(new
                // BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                //                busBudgetAccountingCost.setDisplayNum(totalNum.divide(new
                // BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP).toString());
                busBudgetAccountingCost.setTotalPrice(
                        totalAmount.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                    busBudgetAccountingCost.setDisplayTotalPrice(
                            totalAmount
                                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    busBudgetAccountingCost.setDisplayTotalPrice(
                            totalAmount
                                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                    .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }

                //                if (totalNum.compareTo(new BigDecimal(0)) == 0) {
                //                    busBudgetAccountingCost.setPrice(new BigDecimal(0));
                //                    busBudgetAccountingCost.setDisplayPrice("0");
                //                } else {
                //
                // busBudgetAccountingCost.setPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                //                    if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                //
                // busBudgetAccountingCost.setDisplayPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 0, BigDecimal.ROUND_HALF_UP).toString());
                //                    } else {
                //
                // busBudgetAccountingCost.setDisplayPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 2, BigDecimal.ROUND_HALF_UP).toString());
                //                    }
                //                }
                accountingInfoDao.updateBusBudgetAccountingCostByPrimaryKeySelective(
                        busBudgetAccountingCost);
                // 记录数据---总数量
                BusBudgetAccountingEstimatesData accountingData = new BusBudgetAccountingEstimatesData();
                accountingData.setBatId(param.getBatId());
                accountingData.setProCode(vwProject.getCode());
                accountingData.setUseType(2);
                accountingData.setDataMajor(busBudgetAccountingCost.getMajor());
                accountingData.setDataPart(busBudgetAccountingCost.getPart());
                accountingData.setCostId(busBudgetAccountingCost.getId());
                if (busBudgetAccountingCost.getCode().contains("-外购费")) {
                    //                    accountingData.setDataType("该项目外购费总数量");
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                    // 记录数据---总价
                    accountingData.setDataType("该项目外购费总价");
                    BusBudgetAccountingEstimatesData extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);

                    extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    if (extistsData != null) {
                        accountingData = extistsData;
                        accountingData.setDataValue(totalAmount.toString());
                        accountingData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    } else {
                        accountingData.setDataValue(totalAmount.toString());
                        accountingData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    }
                    //                    //记录数据---单价
                    //                    accountingData.setDataType("该项目外购费单价");
                    //                    extistsData =
                    // accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    //
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                    //                            accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                    // BigDecimal.ROUND_HALF_UP).toString());
                    //                        } else {
                    //                            accountingData.setDataValue("0");
                    //                        }
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                    //                            accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                    // BigDecimal.ROUND_HALF_UP).toString());
                    //                        } else {
                    //                            accountingData.setDataValue("0");
                    //                        }
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                } else if (busBudgetAccountingCost.getCode().contains("备品备件")) {
                    //                    accountingData.setDataType("该项目备品备件总数量");
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                    // 记录数据---总价
                    accountingData.setDataType("该项目备品备件总价");
                    BusBudgetAccountingEstimatesData extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    if (extistsData != null) {
                        accountingData = extistsData;
                        accountingData.setDataValue(totalAmount.toString());
                        accountingData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    } else {
                        accountingData.setDataValue(totalAmount.toString());
                        accountingData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    }
                    //                    //记录数据---单价
                    //                    accountingData.setDataType("该项目备品备件单价");
                    //                    extistsData =
                    // accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    //
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                    //                            accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                    // BigDecimal.ROUND_HALF_UP).toString());
                    //                        } else {
                    //                            accountingData.setDataValue("0");
                    //                        }
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                    //                            accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                    // BigDecimal.ROUND_HALF_UP).toString());
                    //                        } else {
                    //                            accountingData.setDataValue("0");
                    //                        }
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                } else if (busBudgetAccountingCost.getCode().contains("随机备件")) {
                    //                    accountingData.setDataType("该项目随机备件总数量");
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                    // 记录数据---总价
                    accountingData.setDataType("该项目随机备件总价");
                    BusBudgetAccountingEstimatesData extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    if (extistsData != null) {
                        accountingData = extistsData;
                        accountingData.setDataValue(totalAmount.toString());
                        accountingData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    } else {
                        accountingData.setDataValue(totalAmount.toString());
                        accountingData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    }
                    //                    //记录数据---单价
                    //                    accountingData.setDataType("该项目随机备件单价");
                    //                    extistsData =
                    // accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    //
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                    //                            accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                    // BigDecimal.ROUND_HALF_UP).toString());
                    //                        } else {
                    //                            accountingData.setDataValue("0");
                    //                        }
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                    //                            accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                    // BigDecimal.ROUND_HALF_UP).toString());
                    //                        } else {
                    //                            accountingData.setDataValue("0");
                    //                        }
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                }else if (busBudgetAccountingCost.getCode().contains("不可预见")) {
                    //                    accountingData.setDataType("该项目随机备件总数量");
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                    // 记录数据---总价
                    accountingData.setDataType("该项目不可预见总价");
                    BusBudgetAccountingEstimatesData extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    extistsData =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    if(busBudgetAccountingCost.getUnforeseenArtificial()==null){
                        busBudgetAccountingCost.setUnforeseenArtificial(new BigDecimal(0));
                    }
                    if(busBudgetAccountingCost.getUnforeseenOther()==null){
                        busBudgetAccountingCost.setUnforeseenOther(new BigDecimal(0));
                    }
                    totalAmount=totalAmount.add(busBudgetAccountingCost.getUnforeseenArtificial().add(busBudgetAccountingCost.getUnforeseenOther()));
                    if (extistsData != null) {
                        accountingData = extistsData;
                        accountingData.setDataValue(totalAmount.toString());
                        accountingData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    } else {
                        accountingData.setDataValue(totalAmount.toString());
                        accountingData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    }
                    busBudgetAccountingCost.setTotalPrice(
                            totalAmount.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                    if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                        busBudgetAccountingCost.setDisplayTotalPrice(busBudgetAccountingCost.getTotalPrice().setScale(0,BigDecimal.ROUND_HALF_UP).toString());
                    } else {
                        busBudgetAccountingCost.setDisplayTotalPrice(
                                busBudgetAccountingCost.getTotalPrice()
                                        .divide(divisor, 2, BigDecimal.ROUND_HALF_UP).setScale(2,BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    accountingInfoDao.updateBusBudgetAccountingCostTotalPriceByPrimarkKey(busBudgetAccountingCost);
                    //                    //记录数据---单价
                    //                    accountingData.setDataType("该项目随机备件单价");
                    //                    extistsData =
                    // accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    //
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                    //                            accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                    // BigDecimal.ROUND_HALF_UP).toString());
                    //                        } else {
                    //                            accountingData.setDataValue("0");
                    //                        }
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                    //                            accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                    // BigDecimal.ROUND_HALF_UP).toString());
                    //                        } else {
                    //                            accountingData.setDataValue("0");
                    //                        }
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                }
            }
            resultMap.put("totalAmount", totalAmount);
            resultMap.put("totalAmountTax", totalAmountTax);
            resultMap.put("busBudgetAccountingCost", busBudgetAccountingCost);
            jsonResult.setData(resultMap);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("计算成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("计算失败！");
            log.error("计算失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    //    /**
    //     *  automaticCalculationPur
    //     *  自动计算
    //     * @param param
    //     * @return com.zhongwang.business.common.JsonResult
    //     * @author 徐一贺
    //     * @date 2020/10/10 14:04
    //     * @version 1.0
    //     **********************************************
    //     */
    //    @Transactional(rollbackFor = Exception.class)
    //    public JsonResult automaticCalculationPur(BusBudgetAccountingCost param) {
    //        JsonResult jsonResult = new JsonResult();
    //        try {
    //            //获取税
    //            BusBudgetAccountingBasicInfoConfig busBudgetAccountingBasicInfoConfig =
    // accountingInfoDao.getBusBudgetAccountingBasicInfoConfigByPrimaryKeyAndCode(param.getBatId(),
    // "tax");
    //            BigDecimal tax = new BigDecimal(busBudgetAccountingBasicInfoConfig.getValue());
    //            //获取总金额(不含税)
    //            BigDecimal totalAmount = accountingInfoDao.getPurTotalAmount(param);
    //            if (totalAmount != null) {
    //                //获取总金额含税
    //                BigDecimal totalAmountTax = totalAmount.multiply(tax);
    //                //设置该成本项的状态为执行中
    //                BusBudgetAccountingCost busBudgetAccountingCost =
    // accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
    //                busBudgetAccountingCost.setFinishStatus(2);
    //
    // accountingInfoDao.updateBusBudgetAccountingCostFinishStatusByPrimaryKeySelective(busBudgetAccountingCost);
    //
    // accountingInfoDao.updateBusBudgetAccountingCostAmountInfo(busBudgetAccountingCost);
    //                //
    //                //设置返回体内容
    //                Map<String, Object> resultMap = new HashMap();
    //                resultMap.put("tax", tax);
    //                resultMap.put("totalAmount", totalAmount);
    //                resultMap.put("totalAmountTax", totalAmountTax);
    //                resultMap.put("busBudgetAccountingCost", busBudgetAccountingCost);
    //                jsonResult.setData(resultMap);
    //                jsonResult.setType(JsonResult.ResultType.SUCCESS);
    //                jsonResult.setMsg("计算成功！");
    //            } else {
    //                jsonResult.setType(JsonResult.ResultType.ERROR);
    //                jsonResult.setMsg("因部分物料无单价，所以无法核算！");
    //            }
    //
    //        } catch (Exception ex) {
    //            ex.printStackTrace();
    //            jsonResult.setType(JsonResult.ResultType.ERROR);
    //            jsonResult.setMsg("计算失败！");
    //            log.error("外购件计算失败！异常信息如下：" + ex.getMessage());
    //        }
    //        return jsonResult;
    //    }

    /**
     * automaticCalculationWholeOut 整体外协自动计算
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020年11月5日07:54:54
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult automaticCalculationWholeOut(BusBudgetAccountingCost param) {
        JsonResult jsonResult = new JsonResult();
        try {
            // 设置该成本项的状态为已完成
            BusBudgetAccountingCost busBudgetAccountingCost =
                    accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
            // 设置被除数
            BigDecimal divisor = new BigDecimal(0);
            switch (busBudgetAccountingCost.getAmountDisplayModel().intValue()) {
                case 1:
                    divisor = new BigDecimal(1);
                    break;
                case 2:
                    divisor = new BigDecimal(10000);
                    break;
                case 3:
                    divisor = new BigDecimal(1000000);
                    break;
                default:
                    divisor = new BigDecimal(100000000);
                    break;
            }
            busBudgetAccountingCost.setFinishStatus(3);
            accountingInfoDao.updateBusBudgetAccountingCostFinishStatusByPrimaryKeySelective(
                    busBudgetAccountingCost);
            BusBudgetAccountingTaskModel order =
                    accountingInfoDao.getBusBudgetAccountingTaskModelById(param.getBatId());
            VwProject vwProject = accountingInfoDao.getVwProjectByCode(order.getProCode());
            // 获取税
            BusBudgetAccountingBasicInfoConfig busBudgetAccountingBasicInfoConfig =
                    accountingInfoDao.getBusBudgetAccountingBasicInfoConfigByPrimaryKeyAndCode(
                            param.getBatId(), "tax");
            BigDecimal tax = new BigDecimal(busBudgetAccountingBasicInfoConfig.getValue());
            // 设置返回体内容
            Map<String, Object> resultMap = new HashMap();
            resultMap.put("tax", tax);
            // 获取总金额(含税)
            BigDecimal totalAmountTax = accountingInfoDao.getWholeOutTotalAmount(param);
            // 总金额不含税
            BigDecimal totalAmount = new BigDecimal(0);
            if (totalAmountTax != null) {
                // 获取总金额
                totalAmount =
                        totalAmountTax.divide(
                                new BigDecimal(1).add(
                                        tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), BigDecimal.ROUND_HALF_UP);
                //                //获取总数量
                //                BigDecimal totalNum = accountingInfoDao.getWholeOutTotalNum(param);
                //                //反写 总数量 总价 单价 这些数据皆除以项目数量
                //                busBudgetAccountingCost.setNum(totalNum.divide(new
                // BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                //                busBudgetAccountingCost.setDisplayNum(totalNum.divide(new
                // BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP).toString());
                busBudgetAccountingCost.setTotalPrice(
                        totalAmount.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                    busBudgetAccountingCost.setDisplayTotalPrice(
                            totalAmount
                                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    busBudgetAccountingCost.setDisplayTotalPrice(
                            totalAmount
                                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                    .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
                //                if (totalNum.compareTo(new BigDecimal(0)) == 0) {
                //                    busBudgetAccountingCost.setPrice(new BigDecimal(0));
                //                    busBudgetAccountingCost.setDisplayPrice("0");
                //                } else {
                //
                // busBudgetAccountingCost.setPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                //                    if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                //
                // busBudgetAccountingCost.setDisplayPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 0, BigDecimal.ROUND_HALF_UP).toString());
                //                    } else {
                //
                // busBudgetAccountingCost.setDisplayPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 2, BigDecimal.ROUND_HALF_UP).toString());
                //                    }
                //                }
                accountingInfoDao.updateBusBudgetAccountingCostByPrimaryKeySelective(
                        busBudgetAccountingCost);
                // 记录数据---总数量
                BusBudgetAccountingEstimatesData accountingData = new BusBudgetAccountingEstimatesData();
                accountingData.setBatId(param.getBatId());
                accountingData.setProCode(vwProject.getCode());
                accountingData.setUseType(2);
                accountingData.setDataMajor(busBudgetAccountingCost.getMajor());
                accountingData.setDataPart(busBudgetAccountingCost.getPart());
                accountingData.setCostId(busBudgetAccountingCost.getId());
                if (busBudgetAccountingCost.getCode().contains("-外协费-整体外协")) {
                    //                    accountingData.setDataType("该项目外协费整体外协总数量");
                    //                    BusBudgetAccountingEstimatesData extistsData =
                    // accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                    //                    if (extistsData != null) {
                    //                        accountingData = extistsData;
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                    //                    } else {
                    //                        accountingData.setDataValue(totalNum.toString());
                    //                        accountingData.setDataUnit("件");
                    //
                    // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                    //                    }
                }
                // 记录数据---总价
                accountingData.setDataType("该项目外协费整体外协总价");
                BusBudgetAccountingEstimatesData extistsData =
                        accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                if (extistsData != null) {
                    accountingData = extistsData;
                    accountingData.setDataValue(totalAmount.toString());
                    accountingData.setDataUnit("元");
                    accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                } else {
                    accountingData.setDataValue(totalAmount.toString());
                    accountingData.setDataUnit("元");
                    accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                }
                //                //记录数据---单价
                //                accountingData.setDataType("该项目外协费整体外协单价");
                //                extistsData =
                // accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                //
                //                if (extistsData != null) {
                //                    accountingData = extistsData;
                //                    if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                //                        accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                // BigDecimal.ROUND_HALF_UP).toString());
                //                    } else {
                //                        accountingData.setDataValue("0");
                //                    }
                //
                // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                //                } else {
                //                    if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                //                        accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                // BigDecimal.ROUND_HALF_UP).toString());
                //                    } else {
                //                        accountingData.setDataValue("0");
                //                    }
                //
                // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                //                }
            }
            resultMap.put("totalAmount", totalAmount);
            resultMap.put("totalAmountTax", totalAmountTax);
            resultMap.put("busBudgetAccountingCost", busBudgetAccountingCost);
            jsonResult.setData(resultMap);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("计算成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("计算失败！");
            log.error("原材料计算失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * automaticCalculationWithMatOut 带料外协自动计算
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020年11月5日07:54:54
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult automaticCalculationWithMatOut(BusBudgetAccountingCost param) {
        JsonResult jsonResult = new JsonResult();
        try {
            // 设置该成本项的状态为已完成
            BusBudgetAccountingCost busBudgetAccountingCost =
                    accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
            // 设置被除数
            BigDecimal divisor = new BigDecimal(0);
            switch (busBudgetAccountingCost.getAmountDisplayModel().intValue()) {
                case 1:
                    divisor = new BigDecimal(1);
                    break;
                case 2:
                    divisor = new BigDecimal(10000);
                    break;
                case 3:
                    divisor = new BigDecimal(1000000);
                    break;
                default:
                    divisor = new BigDecimal(100000000);
                    break;
            }
            busBudgetAccountingCost.setFinishStatus(3);
            accountingInfoDao.updateBusBudgetAccountingCostFinishStatusByPrimaryKeySelective(
                    busBudgetAccountingCost);
            BusBudgetAccountingTaskModel order =
                    accountingInfoDao.getBusBudgetAccountingTaskModelById(param.getBatId());
            VwProject vwProject = accountingInfoDao.getVwProjectByCode(order.getProCode());
            // 获取税
            BusBudgetAccountingBasicInfoConfig busBudgetAccountingBasicInfoConfig =
                    accountingInfoDao.getBusBudgetAccountingBasicInfoConfigByPrimaryKeyAndCode(
                            param.getBatId(), "tax");
            BigDecimal tax = new BigDecimal(busBudgetAccountingBasicInfoConfig.getValue());
            // 设置返回体内容
            Map<String, Object> resultMap = new HashMap();
            resultMap.put("tax", tax);
            // 获取总金额(含税)
            BigDecimal totalAmountTax = accountingInfoDao.getWithMatOutTotalAmount(param);
            // 总金额不含税
            BigDecimal totalAmount = new BigDecimal(0);
            if (totalAmountTax != null) {
                // 获取总金额
                totalAmount =
                        totalAmountTax.divide(
                                new BigDecimal(1).add(tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP);
                //                //获取总数量
                //                BigDecimal totalNum = accountingInfoDao.getWithMatOutTotalNum(param);
                //                //反写 总数量 总价 单价 这些数据皆除以项目数量
                //                busBudgetAccountingCost.setNum(totalNum.divide(new
                // BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                //                busBudgetAccountingCost.setDisplayNum(totalNum.divide(new
                // BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP).toString());

                if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                    busBudgetAccountingCost.setDisplayTotalPrice(
                            totalAmount
                                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    busBudgetAccountingCost.setDisplayTotalPrice(
                            totalAmount
                                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                    .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
                busBudgetAccountingCost.setTotalPrice(
                        totalAmount.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
                //                if (totalNum.compareTo(new BigDecimal(0)) == 0) {
                //                    busBudgetAccountingCost.setPrice(new BigDecimal(0));
                //                    busBudgetAccountingCost.setDisplayPrice("0");
                //                } else {
                //
                // busBudgetAccountingCost.setPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                //                    if (busBudgetAccountingCost.getAmountDisplayModel().intValue() == 1) {
                //
                // busBudgetAccountingCost.setDisplayPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 0, BigDecimal.ROUND_HALF_UP).toString());
                //                    } else {
                //
                // busBudgetAccountingCost.setDisplayPrice(busBudgetAccountingCost.getTotalPrice().divide(busBudgetAccountingCost.getNum(), 2, BigDecimal.ROUND_HALF_UP).toString());
                //                    }
                //                }
                accountingInfoDao.updateBusBudgetAccountingCostByPrimaryKeySelective(
                        busBudgetAccountingCost);
                // 记录数据---总数量
                BusBudgetAccountingEstimatesData accountingData = new BusBudgetAccountingEstimatesData();
                accountingData.setBatId(param.getBatId());
                accountingData.setProCode(vwProject.getCode());
                accountingData.setUseType(2);
                accountingData.setDataMajor(busBudgetAccountingCost.getMajor());
                accountingData.setDataPart(busBudgetAccountingCost.getPart());
                accountingData.setCostId(busBudgetAccountingCost.getId());
                //                if (busBudgetAccountingCost.getCode().contains("-外协费-带料外协")
                //                ) {
                //                    accountingData.setDataType("该项目外协费带料外协总数量");
                //                    BusBudgetAccountingEstimatesData extistsData =
                // accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                //                    if (extistsData != null) {
                //                        accountingData = extistsData;
                //                        accountingData.setDataValue(totalNum.toString());
                //                        accountingData.setDataUnit("件");
                //
                // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                //                    } else {
                //                        accountingData.setDataValue(totalNum.toString());
                //                        accountingData.setDataUnit("件");
                //
                // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                //                    }
                //                }
                // 记录数据---总价
                accountingData.setDataType("该项目外协费带料外协总价");
                BusBudgetAccountingEstimatesData extistsData =
                        accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                if (extistsData != null) {
                    accountingData = extistsData;
                    accountingData.setDataValue(totalAmount.toString());
                    accountingData.setDataUnit("元");
                    accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                } else {
                    accountingData.setDataValue(totalAmount.toString());
                    accountingData.setDataUnit("元");
                    accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                }
                //                //记录数据---单价
                //                accountingData.setDataType("该项目外协费带料外协单价");
                //                extistsData =
                // accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(accountingData);
                //
                //                if (extistsData != null) {
                //                    accountingData = extistsData;
                //                    if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                //                        accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                // BigDecimal.ROUND_HALF_UP).toString());
                //                    } else {
                //                        accountingData.setDataValue("0");
                //                    }
                //
                // accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(accountingData);
                //                } else {
                //                    if (totalNum.compareTo(new BigDecimal(0)) == 1) {
                //                        accountingData.setDataValue(totalAmount.divide(totalNum, 8,
                // BigDecimal.ROUND_HALF_UP).toString());
                //                    } else {
                //                        accountingData.setDataValue("0");
                //                    }
                //
                // accountingInfoDao.insertBusBudgetAccountingEstimatesData(accountingData);
                //                }
            }
            resultMap.put("totalAmount", totalAmount);
            resultMap.put("totalAmountTax", totalAmountTax);
            resultMap.put("busBudgetAccountingCost", busBudgetAccountingCost);
            jsonResult.setData(resultMap);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("计算成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("计算失败！");
            log.error("带料外协计算失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * calculationFinish 计算完结
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/10 15:09
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult calculationFinish(BusBudgetAccountingCost param) {
        JsonResult jsonResult = new JsonResult();
        try {
            // 设置该成本项的状态为已完成
            BusBudgetAccountingCost busBudgetAccountingCost =
                    accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
            busBudgetAccountingCost.setFinishStatus(3);
            accountingInfoDao.updateBusBudgetAccountingCostFinishStatusByPrimaryKeySelective(
                    busBudgetAccountingCost);
            // 设置返回体内容
            Map<String, Object> resultMap = new HashMap();
            resultMap.put("busBudgetAccountingCost", busBudgetAccountingCost);
            jsonResult.setData(resultMap);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("计算成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("计算失败！");
            log.error("原材料计算失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * cancelCalculationFinishRawMaterial 计算完结
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/10/10 15:09
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult cancelCalculationFinishRawMaterial(BusBudgetAccountingCost param) {
        JsonResult jsonResult = new JsonResult();
        try {
            // 设置该成本项的状态为执行中
            BusBudgetAccountingCost busBudgetAccountingCost =
                    accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
            busBudgetAccountingCost.setFinishStatus(2);
            accountingInfoDao.updateBusBudgetAccountingCostFinishStatusByPrimaryKeySelective(
                    busBudgetAccountingCost);
            // 设置返回体内容
            Map<String, Object> resultMap = new HashMap();
            resultMap.put("busBudgetAccountingCost", busBudgetAccountingCost);
            jsonResult.setData(resultMap);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("完成成功！");
        } catch (Exception ex) {
            ex.printStackTrace();
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("完成失败！");
            log.error("完成失败！异常信息如下：" + ex.getMessage());
        }
        return jsonResult;
    }

    /**
     * getConfigParam 根据条件获取基础配置参数
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/5 14:43
     */
    public BusBudgetAccountingBasicInfoConfigModel getConfigParam(
            BusBudgetAccountingBasicInfoConfigModel param) {
        return accountingInfoDao.getConfigParam(param);
    }

    /**
     * getBusBudgetAccountingCostModelByPrimaryKey 根据主键获取成本项
     *
     * @param id 主键
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusBudgetAccountingCostModel
     * @author 徐一贺
     * @date 2020/11/5 20:52
     */
    public BusBudgetAccountingCostModel getBusBudgetAccountingCostModelByPrimaryKey(Integer id) {
        return new BusBudgetAccountingCostModel(
                accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(id));
    }

    /**
     * findBusGeneralHoursModelListByCondition 根据条件获取、工时、辅材、重量、运费等数据。
     *
     * @param condition 条件
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusGeneralHoursModel>
     * @author 徐一贺
     * @date 2020/11/6 8:31
     */
    public List<BusGeneralHoursModel> findBusGeneralHoursModelListByCondition(
            BusGeneralHoursModel condition) {
        return accountingInfoDao.findBusGeneralHoursModelListByCondition(condition);
    }

    /**
     * automaticCalculationCut 自动计算
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/6 10:58
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult automaticCalculationWorkAndMat(BusGeneralHoursModel param) {
        BigDecimal result = new BigDecimal(0);
        // 根据主键获取成本项
        BusBudgetAccountingCost costInfo =
                accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(param.getId());
        // 获取显示金额模式需要除金额
        BigDecimal divisor = new BigDecimal(0);
        switch (costInfo.getAmountDisplayModel()) {
            // 元
            case 1:
                divisor = new BigDecimal(1);
                break;
            // 万元
            case 2:
                divisor = new BigDecimal(10000);
                break;
            // 百万
            case 3:
                divisor = new BigDecimal(1000000);
                break;
            // 亿
            default:
                divisor = new BigDecimal(100000000);
                break;
        }

        // 获取单据表
        BusBudgetAccountingTaskModel taskModel =
                accountingInfoDao.getBusBudgetAccountingTaskModelById(param.getBatId());
        // 获取项目表
        VwProject vwProject = accountingInfoDao.getVwProjectByCode(taskModel.getProCode());
        param.setBatId(costInfo.getBatId());
        param.setDataUseType(2);
        Map<String, Object> resultMap = new HashMap<>();
        BusBudgetAccountingBasicInfoConfigModel params = new BusBudgetAccountingBasicInfoConfigModel();
        params.setBatId(costInfo.getBatId());
        params.setCode("tax");
        BigDecimal tax = new BigDecimal(accountingInfoDao.getConfigParam(params).getValue());
        BusMachiningHoursModel macCondition = new BusMachiningHoursModel();
        Integer auxiliaryMaterialsCount = 0;
        BigDecimal totalWorkHours = new BigDecimal(0);
        BusBudgetAccountingEstimatesData budgetAccountingEstimatesData =
                new BusBudgetAccountingEstimatesData();
        budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
        budgetAccountingEstimatesData.setCostId(costInfo.getId());
        budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
        budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
        budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
        budgetAccountingEstimatesData.setUseType(2);
        BigDecimal notHaveTax = new BigDecimal(0);
        // 机械、流体、自动化下料工时
        if (costInfo.getCode().contains("-制造费-下料")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("7");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("8");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("9");
            }
            param.setLaborTypes("4");
            params.setBatId(costInfo.getBatId());
            params.setCode("Average daily wage per capita of Zhongwang machinery");
            param.setAverageDailyWagePerCapitaOfZhongwangMachinery(
                    new BigDecimal(accountingInfoDao.getConfigParam(params).getValue()));
            result = accountingInfoDao.automaticCalculationCutWorkHoursCost(param);
            totalWorkHours = accountingInfoDao.GetTotalWorkHoursByParam(param);
            if (result != null) {
                param.setLaborTypes("5");
                // 获取辅材数据数量
                auxiliaryMaterialsCount = accountingInfoDao.getCutAuxiliaryMaterialsCount(param);
                if (auxiliaryMaterialsCount > 0) {
                    BigDecimal auxiliaryMaterialsTotalPrice =
                            accountingInfoDao.automaticCalculationCutMat(param);
                    notHaveTax =
                            auxiliaryMaterialsTotalPrice
                                    .divide(
                                            new BigDecimal(1).add(
                                                    tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)),8, BigDecimal.ROUND_HALF_UP)
                                    .setScale(8, BigDecimal.ROUND_HALF_UP);
                    budgetAccountingEstimatesData.setDataType("该项目制造费下料不含税总价");
                    // 总价含税
                    BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                    budgetAccountingEstimatesData);
                    if (cutTotalTaxPrice != null) {
                        budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                        budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                                budgetAccountingEstimatesData);
                    } else {
                        budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                    }
                    result = result.add(auxiliaryMaterialsTotalPrice);
                } else {
                    budgetAccountingEstimatesData.setDataType("该项目制造费下料不含税总价");
                    // 总价含税
                    BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                    budgetAccountingEstimatesData);
                    if (cutTotalTaxPrice != null) {
                        budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                        budgetAccountingEstimatesData.setDataValue(result.toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                                budgetAccountingEstimatesData);
                    } else {
                        budgetAccountingEstimatesData.setDataValue(result.toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                    }
                }
                resultMap.put("amount", result);
            }
            // 总工时
            budgetAccountingEstimatesData.setDataType("该项目制造费下料总工时");
            BusBudgetAccountingEstimatesData cutTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (cutTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(cutTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价含税
            budgetAccountingEstimatesData.setDataType("该项目制造费下料总价");
            BusBudgetAccountingEstimatesData cutTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (cutTotalPrice != null) {
                budgetAccountingEstimatesData.setId(cutTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));

            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    totalWorkHours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
        } else if (costInfo.getCode().contains("-制造费-铆焊")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("13");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("14");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("15");
            }
            param.setLaborTypes("6");
            params.setBatId(costInfo.getBatId());
            params.setCode("Average daily wage per capita of Zhongwang machinery");
            param.setAverageDailyWagePerCapitaOfZhongwangMachinery(
                    new BigDecimal(accountingInfoDao.getConfigParam(params).getValue()));
            result = accountingInfoDao.automaticCalculationCutWorkHoursCost(param);
            totalWorkHours = accountingInfoDao.GetTotalWorkHoursByParam(param);
            if (result != null) {
                param.setLaborTypes("7");
                // 获取辅材数据数量
                auxiliaryMaterialsCount = accountingInfoDao.getCutAuxiliaryMaterialsCount(param);
                if (auxiliaryMaterialsCount > 0) {
                    BigDecimal auxiliaryMaterialsTotalPrice =
                            accountingInfoDao.automaticCalculationCutMat(param);
                    notHaveTax =
                            auxiliaryMaterialsTotalPrice
                                    .divide(
                                            new BigDecimal(1).add(
                                                    tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP)
                                    .setScale(8, BigDecimal.ROUND_HALF_UP);
                    budgetAccountingEstimatesData.setDataType("该项目制造费铆焊不含税总价");
                    // 总价含税
                    BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                    budgetAccountingEstimatesData);
                    if (cutTotalTaxPrice != null) {
                        budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                        budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                                budgetAccountingEstimatesData);
                    } else {
                        budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                    }
                    result = result.add(auxiliaryMaterialsTotalPrice);
                } else {
                    budgetAccountingEstimatesData.setDataType("该项目制造费铆焊不含税总价");
                    // 总价含税
                    BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                    budgetAccountingEstimatesData);
                    if (cutTotalTaxPrice != null) {
                        budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                        budgetAccountingEstimatesData.setDataValue(result.toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                                budgetAccountingEstimatesData);
                    } else {
                        budgetAccountingEstimatesData.setDataValue(result.toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                    }
                }
                resultMap.put("amount", result);
            }
            // 总工时
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目制造费铆焊总工时");
            BusBudgetAccountingEstimatesData rivetAndSolderTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (rivetAndSolderTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(rivetAndSolderTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目制造费铆焊总价");
            BusBudgetAccountingEstimatesData rivetAndSolderTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (rivetAndSolderTotalPrice != null) {
                budgetAccountingEstimatesData.setId(rivetAndSolderTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    totalWorkHours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
        } else if (costInfo.getCode().contains("-制造费-机加")) {
            macCondition.setBatId(costInfo.getBatId());
            macCondition.setMajor(costInfo.getMajor());
            macCondition.setPart(costInfo.getPart());
            macCondition.setDataUseType(2);
            // 总价
            result = accountingInfoDao.getTotalPriceBusMachiningHoursModelByCondition(macCondition);
            // 总工时
            BigDecimal macTotalhours = accountingInfoDao.getBusMachiningHoursByCondition(macCondition);

            resultMap.put("amount", result);
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目制造费机加总工时");
            BusBudgetAccountingEstimatesData macTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (macTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(macTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(macTotalhours.toString());
                budgetAccountingEstimatesData.setDataUnit("工时");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(macTotalhours.toString());
                budgetAccountingEstimatesData.setDataUnit("工时");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目制造费机加总价");
            BusBudgetAccountingEstimatesData macTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (macTotalPrice != null) {
                budgetAccountingEstimatesData.setId(macTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    macTotalhours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    macTotalhours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (macTotalhours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
        }
        // 机械 流体 自动化 喷涂
        else if (costInfo.getCode().contains("-制造费-喷涂")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("25");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("26");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("27");
            }
            param.setLaborTypes("9,11");
            params.setBatId(costInfo.getBatId());
            params.setCode("Average daily wage per capita of Zhongwang machinery");
            param.setAverageDailyWagePerCapitaOfZhongwangMachinery(
                    new BigDecimal(accountingInfoDao.getConfigParam(params).getValue()));
            result = accountingInfoDao.automaticCalculationCutWorkHoursCost(param);
            totalWorkHours = accountingInfoDao.GetTotalWorkHoursByParam(param);
            if (result != null) {
                param.setLaborTypes("10,12");
                // 获取辅材数据数量
                auxiliaryMaterialsCount = accountingInfoDao.getCutAuxiliaryMaterialsCount(param);
                if (auxiliaryMaterialsCount > 0) {
                    BigDecimal auxiliaryMaterialsTotalPrice =
                            accountingInfoDao.automaticCalculationCutMat(param);
                    notHaveTax =
                            auxiliaryMaterialsTotalPrice
                                    .divide(
                                            new BigDecimal(1).add(
                                                    tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP)
                                    .setScale(8, BigDecimal.ROUND_HALF_UP);
                    budgetAccountingEstimatesData.setDataType("该项目制造费喷涂不含税总价");
                    // 总价含税
                    BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                    budgetAccountingEstimatesData);
                    if (cutTotalTaxPrice != null) {
                        budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                        budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                                budgetAccountingEstimatesData);
                    } else {
                        budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                    }
                    result = result.add(auxiliaryMaterialsTotalPrice);
                } else {
                    budgetAccountingEstimatesData.setDataType("该项目制造费喷涂不含税总价");
                    // 总价含税
                    BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                    budgetAccountingEstimatesData);
                    if (cutTotalTaxPrice != null) {
                        budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                        budgetAccountingEstimatesData.setDataValue(result.toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                                budgetAccountingEstimatesData);
                    } else {
                        budgetAccountingEstimatesData.setDataValue(result.toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                    }
                }
                resultMap.put("amount", result);
            }
            // 总工时
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目制造费喷涂总工时");
            BusBudgetAccountingEstimatesData sprayTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (sprayTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(sprayTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目制造费喷涂总价");
            BusBudgetAccountingEstimatesData sprayTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (sprayTotalPrice != null) {
                budgetAccountingEstimatesData.setId(sprayTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    totalWorkHours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
        }
        // 机械 流体 自动化 装配
        else if (costInfo.getCode().contains("-制造费-装配")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("31");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("32");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("33");
            }
            param.setLaborTypes("13");
            params.setBatId(costInfo.getBatId());
            params.setCode("Average daily wage per capita of Zhongwang machinery");
            param.setAverageDailyWagePerCapitaOfZhongwangMachinery(
                    new BigDecimal(accountingInfoDao.getConfigParam(params).getValue()));
            result = accountingInfoDao.automaticCalculationCutWorkHoursCost(param);
            totalWorkHours = accountingInfoDao.GetTotalWorkHoursByParam(param);
            if (result != null) {
                param.setLaborTypes("14");
                // 获取辅材数据数量
                auxiliaryMaterialsCount = accountingInfoDao.getCutAuxiliaryMaterialsCount(param);
                if (auxiliaryMaterialsCount > 0) {
                    BigDecimal auxiliaryMaterialsTotalPrice =
                            accountingInfoDao.automaticCalculationCutMat(param);
                    notHaveTax =
                            auxiliaryMaterialsTotalPrice
                                    .divide(
                                            new BigDecimal(1).add(
                                                    tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP)
                                    .setScale(8, BigDecimal.ROUND_HALF_UP);
                    budgetAccountingEstimatesData.setDataType("该项目制造费装配不含税总价");
                    // 总价含税
                    BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                    budgetAccountingEstimatesData);
                    if (cutTotalTaxPrice != null) {
                        budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                        budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                                budgetAccountingEstimatesData);
                    } else {
                        budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                    }
                    result = result.add(auxiliaryMaterialsTotalPrice);
                } else {
                    budgetAccountingEstimatesData.setDataType("该项目制造费装配不含税总价");
                    // 总价含税
                    BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                            accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                    budgetAccountingEstimatesData);
                    if (cutTotalTaxPrice != null) {
                        budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                        budgetAccountingEstimatesData.setDataValue(result.toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                                budgetAccountingEstimatesData);
                    } else {
                        budgetAccountingEstimatesData.setDataValue(result.toString());
                        budgetAccountingEstimatesData.setDataUnit("元");
                        accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                    }
                }
                resultMap.put("amount", result);
            }
            // 总工时
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目制造费装配总工时");
            BusBudgetAccountingEstimatesData assemblingTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (assemblingTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(assemblingTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目制造费装配总价");
            BusBudgetAccountingEstimatesData assemblingTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (assemblingTotalPrice != null) {
                budgetAccountingEstimatesData.setId(assemblingTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    totalWorkHours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
        }
        // 机械 流体 自动化 热处理
        else if (costInfo.getCode().contains("-制造费-热处理")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("19");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("20");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("21");
            }
            param.setLaborTypes("8");
            params.setBatId(costInfo.getBatId());
            result = accountingInfoDao.automaticCalculationCutWorkHoursCostHeatTreatment(param);
            totalWorkHours =
                    accountingInfoDao
                            .GetTotalWorkHoursByParam(param)
                            .divide(new BigDecimal(1000), 8, BigDecimal.ROUND_HALF_UP);
            // 总重量
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目制造费热处理总重量");
            BusBudgetAccountingEstimatesData heatTreatmentTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (heatTreatmentTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(heatTreatmentTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("吨");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("吨");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目制造费热处理总价");
            BusBudgetAccountingEstimatesData heatTreatmentTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (heatTreatmentTotalPrice != null) {
                budgetAccountingEstimatesData.setId(heatTreatmentTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    totalWorkHours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
            resultMap.put("amount", result);
        }
        // 机械 流体 自动化 现场安装调试费---人工---安装人工
        else if (costInfo.getCode().contains("-现场安装费-人工-安装人工")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("38");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("39");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("40");
            }
            param.setLaborTypes("18");
            params.setBatId(costInfo.getBatId());
            params.setCode("Per capita wage of site installation");
            param.setAverageDailyWagePerCapitaOfZhongwangMachinery(
                    new BigDecimal(accountingInfoDao.getConfigParam(params).getValue()));
            result = accountingInfoDao.automaticCalculationCutWorkHoursCost(param);
            totalWorkHours = accountingInfoDao.GetTotalWorkHoursByParam(param);
            // 总工时
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目现场安装费人工安装人工总工时");
            BusBudgetAccountingEstimatesData installTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (installTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(installTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目现场安装费人工安装人工总价");
            BusBudgetAccountingEstimatesData installTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (installTotalPrice != null) {
                budgetAccountingEstimatesData.setId(installTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    totalWorkHours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
            resultMap.put("amount", result);
        }
        // 机械 流体 自动化 现场安装调试费---人工---调试人工
        else if (costInfo.getCode().contains("-现场安装费-人工-调试人工")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("1");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("2");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("3");
            }
            param.setLaborTypes("20");
            params.setBatId(costInfo.getBatId());
            params.setCode("Per capita wage of site installation");
            param.setAverageDailyWagePerCapitaOfZhongwangMachinery(
                    new BigDecimal(accountingInfoDao.getConfigParam(params).getValue()));
            result = accountingInfoDao.automaticCalculationCutWorkHoursCost(param);
            totalWorkHours = accountingInfoDao.GetTotalWorkHoursByParam(param);
            // 总工时
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目现场安装费人工调试人工总工时");
            BusBudgetAccountingEstimatesData debugTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (debugTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(debugTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目现场安装费人工调试人工总价");
            BusBudgetAccountingEstimatesData debugTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (debugTotalPrice != null) {
                budgetAccountingEstimatesData.setId(debugTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    totalWorkHours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
            resultMap.put("amount", result);
        }
        // 机械 流体 自动化 现场安装调试费---安装辅材
        else if (costInfo.getCode().contains("-现场安装费-辅材")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("38");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("39");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("40");
            }
            param.setLaborTypes("19");
            params.setBatId(costInfo.getBatId());
            // 总价
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            // 获取辅材数据数量该项目制造费装配不含税总价
            auxiliaryMaterialsCount = accountingInfoDao.getCutAuxiliaryMaterialsCount(param);
            if (auxiliaryMaterialsCount > 0) {
                BigDecimal auxiliaryMaterialsTotalPrice =
                        accountingInfoDao.automaticCalculationCutMat(param);
                notHaveTax =
                        auxiliaryMaterialsTotalPrice
                                .divide(
                                        new BigDecimal(1).add(
                                                tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP);
                budgetAccountingEstimatesData.setDataType("该项目现场安装费安装人工辅材不含税总价");
                // 总价含税
                BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                        accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                budgetAccountingEstimatesData);
                if (cutTotalTaxPrice != null) {
                    budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                    budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                    budgetAccountingEstimatesData.setDataUnit("元");
                    accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                            budgetAccountingEstimatesData);
                } else {
                    budgetAccountingEstimatesData.setDataValue(result.add(notHaveTax).toString());
                    budgetAccountingEstimatesData.setDataUnit("元");
                    accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                }
                result = result.add(auxiliaryMaterialsTotalPrice);
            } else {
                budgetAccountingEstimatesData.setDataType("该项目现场安装费安装人工辅材不含税总价");
                // 总价含税
                BusBudgetAccountingEstimatesData cutTotalTaxPrice =
                        accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                                budgetAccountingEstimatesData);
                if (cutTotalTaxPrice != null) {
                    budgetAccountingEstimatesData.setId(cutTotalTaxPrice.getId());
                    budgetAccountingEstimatesData.setDataValue(result.toString());
                    budgetAccountingEstimatesData.setDataUnit("元");
                    accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                            budgetAccountingEstimatesData);
                } else {
                    budgetAccountingEstimatesData.setDataValue(result.toString());
                    budgetAccountingEstimatesData.setDataUnit("元");
                    accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
                }
            }
            budgetAccountingEstimatesData.setDataType("该项目现场安装费安装人工辅材总价");
            BusBudgetAccountingEstimatesData auxMatTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (auxMatTotalPrice != null) {
                budgetAccountingEstimatesData.setId(auxMatTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            resultMap.put("amount", result);
        }
        // 机械 流体 自动化 设计费
        else if (costInfo.getCode().contains("-设计费")) {
            param.setMajor(costInfo.getMajor());
            param.setPart(costInfo.getPart());
            if ("机械".equals(costInfo.getMajor())) {
                param.setTypes("1");
            } else if ("流体".equals(costInfo.getMajor())) {
                param.setTypes("2");
            } else if ("自动化".equals(costInfo.getMajor())) {
                param.setTypes("3");
            }
            param.setLaborTypes("1");
            params.setBatId(costInfo.getBatId());
            params.setCode("Design per capita daily wage");
            param.setAverageDailyWagePerCapitaOfZhongwangMachinery(
                    new BigDecimal(accountingInfoDao.getConfigParam(params).getValue()));
            result = accountingInfoDao.automaticCalculationCutWorkHoursCost(param);
            totalWorkHours = accountingInfoDao.GetTotalWorkHoursByParam(param);
            // 总工时
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目设计费总工时");
            BusBudgetAccountingEstimatesData designTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (designTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(designTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目设计费总价");
            BusBudgetAccountingEstimatesData designTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (designTotalPrice != null) {
                budgetAccountingEstimatesData.setId(designTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            costInfo.setTotalPrice(
                    result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setNum(
                    totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP));
            costInfo.setDisplayNum(
                    totalWorkHours
                            .divide(new BigDecimal(vwProject.getNum()), 2, BigDecimal.ROUND_HALF_UP)
                            .toString());
            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
                costInfo.setPrice(
                        costInfo.getTotalPrice().divide(costInfo.getNum(), 8, BigDecimal.ROUND_HALF_UP));
                if (costInfo.getAmountDisplayModel().intValue() == 1) {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(costInfo.getNum(), 0, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                } else {
                    costInfo.setDisplayPrice(
                            costInfo
                                    .getTotalPrice()
                                    .divide(divisor, 8, BigDecimal.ROUND_HALF_UP)
                                    .divide(costInfo.getNum(), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
            }
            resultMap.put("amount", result);
        }
        // 包装运输费---包装费
        else if (costInfo.getCode().contains("包装运输费-包装费")) {
            param.setTypes("34");
            param.setLaborTypes("15");
            params.setBatId(costInfo.getBatId());
            params.setCode("Average daily wage per capita of Zhongwang machinery");
            param.setAverageDailyWagePerCapitaOfZhongwangMachinery(
                    new BigDecimal(accountingInfoDao.getConfigParam(params).getValue()));
            result = accountingInfoDao.automaticCalculationCutWorkHoursCost(param);
            BigDecimal totalLaborCost = result;
            totalWorkHours = accountingInfoDao.GetTotalWorkHoursByParam(param);
            if (result != null) {
                param.setLaborTypes("16");
                auxiliaryMaterialsCount = accountingInfoDao.getCutAuxiliaryMaterialsCount(param);
                if (auxiliaryMaterialsCount > 0) {
                    result = result.add(accountingInfoDao.automaticCalculationCutMat(param));
                }
                resultMap.put("amount", result);
            }
            // 总工时
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目包装运输费包装总工时");
            BusBudgetAccountingEstimatesData packingTotalWorkHours =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (packingTotalWorkHours != null) {
                budgetAccountingEstimatesData.setId(packingTotalWorkHours.getId());
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(totalWorkHours.toString());
                budgetAccountingEstimatesData.setDataUnit("工日");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            // 总价
            budgetAccountingEstimatesData.setDataType("该项目包装运输费包装总价");
            BusBudgetAccountingEstimatesData packingTotalPrice =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (packingTotalPrice != null) {
                budgetAccountingEstimatesData.setId(packingTotalPrice.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            budgetAccountingEstimatesData.setDataType("该项目包装运输费包装不含税总价");
            BusBudgetAccountingEstimatesData packingTotalPriceNotFax =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (packingTotalPriceNotFax != null) {
                budgetAccountingEstimatesData.setId(packingTotalPriceNotFax.getId());
                budgetAccountingEstimatesData.setDataValue(
                        totalLaborCost
                                .add(
                                        accountingInfoDao
                                                .automaticCalculationCutMat(param)
                                                .divide(
                                                        new BigDecimal(1)
                                                                .add(
                                                                        tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP))
                                .toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(
                        totalLaborCost
                                .add(
                                        accountingInfoDao
                                                .automaticCalculationCutMat(param)
                                                .divide(
                                                        new BigDecimal(1)
                                                                .add(
                                                                        tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP))
                                .toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }

            costInfo.setTotalPrice(totalLaborCost
                    .add(
                            accountingInfoDao
                                    .automaticCalculationCutMat(param)
                                    .divide(
                                            new BigDecimal(1)
                                                    .add(
                                                            tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP))
                    .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP));
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(
                        totalLaborCost
                                .add(
                                        accountingInfoDao
                                                .automaticCalculationCutMat(param)
                                                .divide(
                                                        new BigDecimal(1)
                                                                .add(
                                                                        tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP))
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        totalLaborCost
                                .add(
                                        accountingInfoDao
                                                .automaticCalculationCutMat(param)
                                                .divide(
                                                        new BigDecimal(1)
                                                                .add(
                                                                        tax.divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 8, BigDecimal.ROUND_HALF_UP))
                                .divide(new BigDecimal(vwProject.getNum()), 0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            //            costInfo.setNum(totalWorkHours.divide(new BigDecimal(vwProject.getNum()), 8,
            // BigDecimal.ROUND_HALF_UP));
            //            costInfo.setDisplayNum(totalWorkHours.divide(new BigDecimal(vwProject.getNum()),
            // 2, BigDecimal.ROUND_HALF_UP).toString());
            //            if (totalWorkHours.compareTo(new BigDecimal(0)) == 1) {
            //                costInfo.setPrice(costInfo.getTotalPrice().divide(costInfo.getNum(), 8,
            // BigDecimal.ROUND_HALF_UP));
            //                if (costInfo.getAmountDisplayModel().intValue() == 1) {
            //
            // costInfo.setDisplayPrice(costInfo.getTotalPrice().divide(costInfo.getNum(), 0,
            // BigDecimal.ROUND_HALF_UP).toString());
            //                } else {
            //                    costInfo.setDisplayPrice(costInfo.getTotalPrice().divide(divisor, 8,
            // BigDecimal.ROUND_HALF_UP).divide(costInfo.getNum(), 2,
            // BigDecimal.ROUND_HALF_UP).toString());
            //                }
            //            }
            resultMap.put("amount", result);
        }
        // 包装运输费---运输费
        else if (costInfo.getCode().contains("包装运输费-运输费")) {
            param.setTypes("34");
            param.setLaborTypes("17");
            param.setBatId(costInfo.getBatId());
            param.setDataUseType(2);
            result = result.add(accountingInfoDao.automaticCalculationTransportationExpenses(param));
            // 总运费
            budgetAccountingEstimatesData.setProCode(taskModel.getProCode());
            budgetAccountingEstimatesData.setCostId(costInfo.getId());
            budgetAccountingEstimatesData.setBatId(costInfo.getBatId());
            budgetAccountingEstimatesData.setDataMajor(costInfo.getMajor());
            budgetAccountingEstimatesData.setDataPart(costInfo.getPart());
            budgetAccountingEstimatesData.setUseType(2);
            budgetAccountingEstimatesData.setDataType("该项目包装运输费运输费");
            BusBudgetAccountingEstimatesData transportationExpenses =
                    accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(
                            budgetAccountingEstimatesData);
            if (transportationExpenses != null) {
                budgetAccountingEstimatesData.setId(transportationExpenses.getId());
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.updateBusBudgetAccountingEstimatesDataByPrimaryKey(
                        budgetAccountingEstimatesData);
            } else {
                budgetAccountingEstimatesData.setDataValue(result.toString());
                budgetAccountingEstimatesData.setDataUnit("元");
                accountingInfoDao.insertBusBudgetAccountingEstimatesData(budgetAccountingEstimatesData);
            }
            BusBudgetAccountingBasicInfoConfigModel freightTaxCondition =
                    new BusBudgetAccountingBasicInfoConfigModel();
            freightTaxCondition.setBatId(costInfo.getBatId());
            freightTaxCondition.setCode("freight tax");
            BusBudgetAccountingBasicInfoConfig freightTax =
                    getBusBudgetAccountingBasicInfoConfigByBatIdAndCode(freightTaxCondition);
            resultMap.put("amount", result);
            result = result.divide(new BigDecimal(vwProject.getNum()), 8, BigDecimal.ROUND_HALF_UP);
            result =
                    result.divide(
                            new BigDecimal(1).add(
                                    new BigDecimal(freightTax.getValue())
                                            .divide(new BigDecimal(100), 8, BigDecimal.ROUND_HALF_UP)), 2, BigDecimal.ROUND_HALF_UP);
            if (costInfo.getAmountDisplayModel().intValue() == 1) {
                costInfo.setDisplayTotalPrice(result.setScale(0, BigDecimal.ROUND_HALF_UP).toString());
            } else {
                costInfo.setDisplayTotalPrice(
                        result
                                .setScale(0, BigDecimal.ROUND_HALF_UP)
                                .divide(divisor, 2, BigDecimal.ROUND_HALF_UP)
                                .toString());
            }
            costInfo.setTotalPrice(result);
        }
        costInfo.setFinishStatus(3);
        accountingInfoDao.updateBusBudgetAccountingCostByPrimaryKeySelective(costInfo);
        resultMap.put("busBudgetAccountingCost", costInfo);
        return JsonResult.success().setData(resultMap);
    }

    /**
     * findBusMachiningHoursModellListByCondition 根据条件获取机加明细列表
     *
     * @param macCondition 条件
     * @return java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusMachiningHoursModel>
     * @author 徐一贺
     * @date 2020/11/7 7:57
     */
    public List<BusMachiningHoursModel> findBusMachiningHoursModelListByCondition(
            BusMachiningHoursModel macCondition) {
        return accountingInfoDao.findBusMachiningHoursModelListByCondition(macCondition);
    }

    /**
     * getVwProjectByCode 根据项目号获取项目实体类
     *
     * @param proCode 项目号
     * @return com.zhongwang.business.gen.entity.VwProject
     * @author 徐一贺
     * @date 2020/11/9 8:50
     */
    public VwProject getVwProjectByCode(String proCode) {
        return getDataDao.getVwProjectByCode(proCode);
    }

    /**
     * getMachiningQuotaData 获取机加定额版本列表
     *
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/9 9:46
     */
    public List<BusMachiningEquipmentQuotaVersion> getMachiningQuotaData() {
        return accountingInfoDao.findBusMachiningEquipmentQuotaVersionList();
    }

    /**
     * AccountingInfoController 根据条件获取机加明细数据
     *
     * @author 徐一贺
     * @date 2020/11/9 11:11
     */
    public List<BusMachiningHoursModel> findMacDetailList(BusMachiningHoursModel param) {
        return accountingInfoDao.findMacDetailList(param);
    }

    /**
     * changeQuotaVersion 更换定额版本
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/11/9 12:45
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult changeQuotaVersion(BusMachiningHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            // 获取机加工时列表
            List<BusMachiningHoursModel> list =
                    accountingInfoDao.findBusMachiningHoursModelListByBatId(param.getBatId());
            // 根据版本号获取定额列表
            List<BusMachiningEquipmentModel> busMachiningEquipmentModelList =
                    accountingInfoDao.findBusMachiningEquipmentModelListByVersion(param.getVersion());
            for (BusMachiningHoursModel model : list) {
                for (BusMachiningEquipmentModel equipmentModel : busMachiningEquipmentModelList) {
                    if (model.getBmeCode().equals(equipmentModel.getCode())) {
                        model.setBmeVersion(equipmentModel.getVersion());
                        accountingInfoDao.updateBusMachiningHoursModelByPrimaryKeySelective(model);
                        BusMachiningEquipmentModel condition = new BusMachiningEquipmentModel();
                        condition.setIsDefault(0);
                        condition.setCode(equipmentModel.getCode());
                        accountingInfoDao.updateBusMachiningEquipmentModelIsDefaultByCode(condition);
                        condition.setIsDefault(1);
                        accountingInfoDao.updateBusMachiningEquipmentModelIsDefaultByPrimaryKey(condition);
                    }
                }
            }
            if (list.size() > 0) {
                BusBudgetAccountingBasicInfoConfigModel condition =
                        new BusBudgetAccountingBasicInfoConfigModel();
                condition.setBatId(list.get(0).getBatId());
                condition.setCode("Machining quota");
                condition.setValue(param.getVersion());
                accountingInfoDao.updateBusBudgetAccountingBasicInfoConfigModelByBatIdAndCode(condition);
            }
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("更换成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("更换失败！");
        }
        return jsonResult;
    }

    /**
     * getBusBudgetAccountingBasicInfoConfigByBatIdAndCode 根据BatId和code获取基础信息配置
     *
     * @param condition 条件
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.BusBudgetAccountingBasicInfoConfigModel
     * @author 徐一贺
     * @date 2020/11/9 15:59
     */
    public BusBudgetAccountingBasicInfoConfigModel
    getBusBudgetAccountingBasicInfoConfigByBatIdAndCode(
            BusBudgetAccountingBasicInfoConfigModel condition) {
        return accountingInfoDao.getBusBudgetAccountingBasicInfoConfigByBatIdAndCode(condition);
    }

    /**
     * getBusBudgetAccountingEstimatesData 根据条件获取预算核算概算数据
     *
     * @param condition 条件
     * @return com.zhongwang.business.gen.entity.BusBudgetAccountingEstimatesData
     * @author 徐一贺
     * @date 2020/11/16 16:51
     */
    public BusBudgetAccountingEstimatesData getBusBudgetAccountingEstimatesData(
            BusBudgetAccountingEstimatesData condition) {
        return accountingInfoDao.getBusBudgetAccountingEstimatesDataByCondition(condition);
    }

    /**
     * rawMatImport 导入原材料数据
     *
     * @param file  文件
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/21 14:44
     */
    public String rawMatImport(MultipartFile file, RawMatModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    RawMatModel.class,
                    new RawMatImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcel(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("清单调整-原材料信息编辑", "原材料数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * AluImport 导入铝材料数据
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/28 10:11
     */
    public String AluImport(MultipartFile file, RawMatModel param) {
        try {
            AluminiumImportModel aluminiumImportModel = new AluminiumImportModel();
            aluminiumImportModel.setId(param.getId());
            aluminiumImportModel.setBatId(param.getBatId());
            aluminiumImportModel.setPart(param.getPart());
            aluminiumImportModel.setMajor(param.getMajor());
            aluminiumImportModel.setTexture(param.getTexture());
            aluminiumImportModel.setMatDesc(param.getMatDesc());
            aluminiumImportModel.setNum(param.getNum());
            aluminiumImportModel.setUnit(param.getUnit());
            aluminiumImportModel.setRemark(param.getRemark());
            aluminiumImportModel.setPrice(param.getPrice());
            aluminiumImportModel.setWarnMessage(param.getWarnMessage());
            aluminiumImportModel.setSapCode(param.getSapCode());
            aluminiumImportModel.setBuyMatDesc(param.getBuyMatDesc());
            aluminiumImportModel.setStandardNo(param.getStandardNo());
            aluminiumImportModel.setBrand(param.getBrand());
            aluminiumImportModel.setDiagram(param.getDiagram());
            aluminiumImportModel.setAssistType(param.getAssistType());
            aluminiumImportModel.setBuyType(param.getBuyType());
            aluminiumImportModel.setMalType(param.getMalType());
            aluminiumImportModel.setDsId(param.getDsId());
            aluminiumImportModel.setUseType(param.getUseType());
            aluminiumImportModel.setProCode(param.getProCode());
            aluminiumImportModel.setBuyNum(param.getBuyNum());
            aluminiumImportModel.setBuyUnit(param.getBuyUnit());
            aluminiumImportModel.setBuyStandardNo(param.getBuyStandardNo());
            aluminiumImportModel.setBuyBrand(param.getBuyBrand());
            aluminiumImportModel.setPriceType(param.getPriceType());
            aluminiumImportModel.setDataType(param.getDataType());
            aluminiumImportModel.setDataUseType(param.getDataUseType());
            aluminiumImportModel.setSourceProCode(param.getSourceProCode());
            aluminiumImportModel.setSourcePart(param.getSourcePart());
            aluminiumImportModel.setGetDate(param.getGetDate());
            aluminiumImportModel.setGetUid(param.getGetUid());
            aluminiumImportModel.setPostName(param.getPostName());
            aluminiumImportModel.setPostTel(param.getPostTel());
            aluminiumImportModel.setPostDept(param.getPostDept());
            FileUtils.importExcel(
                    file,
                    AluminiumImportModel.class,
                    new AluImportListener(
                            aluminiumImportModel,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorAluExcel(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("清单调整-原材料信息编辑", "原材料数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * aluminiumImport 铝材导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @throws
     * @author 徐一贺
     * @date 2020/12/4 20:20
     */
    public String aluminiumImport(MultipartFile file, AluminiumModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    AluminiumModel.class,
                    new AluminiumImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAlum(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算清单编辑-原材料信息编辑", "铝材数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * macImport 导入机加数据
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/30 8:49
     */
    public String macImport(MultipartFile file, MacHoursExportModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    MacHoursExportModel.class,
                    new MacImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelMac(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑-原材料信息编辑", "原材料数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * purImport 导入外购件数据
     *
     * @param file  文件
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/21 14:44
     */
    public String purImport(MultipartFile file, PurModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    PurModel.class,
                    new PurImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelPur(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑-外购件信息编辑", "外购件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * WholeImport 导入整体外协
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/4 14:28
     */
    public String wholeImport(MultipartFile file, WholeExportModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    WholeExportModel.class,
                    new WholeImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelWhole(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑-外购件信息编辑", "外购件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * withMatImport 导入带料外协
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/4 14:42
     */
    public String withMatImport(MultipartFile file, WithMatExportModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    WithMatExportModel.class,
                    new WithMatImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelWithMat(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑-外购件信息编辑", "外购件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * purImport 导入备品备件数据
     *
     * @param file  文件
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/21 14:44
     */
    public String sparePartsImport(MultipartFile file, SparePartsModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    PurModel.class,
                    new SparePartsmportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelSparePart(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑-备品备件信息编辑", "备品备件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * purImport 导入备品备件数据
     *
     * @param file  文件
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/21 14:44
     */
    public String accompanyingSparePartsImport(MultipartFile file, SparePartsModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    PurModel.class,
                    new SparePartsmportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccompanyingSparePart(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑-备品备件信息编辑", "备品备件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * purImport 导入外协件数据
     *
     * @param file  文件
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/21 14:44
     */
    public String outImport(MultipartFile file, OutModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    OutModel.class,
                    new OutImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelOut(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑-外协件信息编辑", "外协件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: weightImport
     * @description: TODO
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/27 10:52
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String weightImport(MultipartFile file, BusBudgetAccountingCost param) {
        try {
            FileUtils.importExcel(
                    file,
                    DesignWeightModel.class,
                    new WeightImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelWeight(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "设计重量数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accPurImport
     * @description: 导入外购件
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 16:53
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accPurImport(MultipartFile file, BusMaterialData param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccPurImportModel.class,
                    new AccPurImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccPur(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "外购件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accRawMatImport
     * @description: 导入原材料
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 19:52
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accRawMatImport(MultipartFile file, BusMaterialData param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccRawMatImportModel.class,
                    new AccRawMatImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccRawMat(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "原材料数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accOutImport
     * @description: 外协件导入
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 20:50
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accOutImport(MultipartFile file, BusMaterialData param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccOutImportModel.class,
                    new AccOutImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccOut(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "外协件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accAluminumImport
     * @description: 铝材导出
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 16:02
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accAluminumImport(MultipartFile file, BusMaterialData param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccAluminiumMatImportModel.class,
                    new AccAluminiumImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccAluminum(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "外协件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accOtherHoursImport
     * @description: 导入其他工时
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 11:45
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accOtherHoursImport(MultipartFile file, BusMaterialData param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccOtherHoursImportModel.class,
                    new AccOtherHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccOtherHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "其他工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accOtherAuxImport
     * @description: 导入其他辅材
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 11:46
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accOtherAuxImport(MultipartFile file, BusMaterialData param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccOtherAuxImportModel.class,
                    new AccOtherAuxImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccOtherAux(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "其他辅材数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accHeatTreatImport
     * @description: 热处理导入
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 13:18
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accHeatTreatImport(MultipartFile file, BusMaterialData param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccHeatTreatmentImportModel.class,
                    new AccHeatTreatmentImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccHeatTreatment(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "热处理数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accMachiningHoursImport
     * @description: 机加工时导入
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 15:05
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accMachiningHoursImport(MultipartFile file, BusMachiningHours param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccMachiningHoursImportModel.class,
                    new AccMachiningHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccMachiningHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "机加工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * @methodName: accTransportationImport
     * @description: 运输费数据导入
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 13:46
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String accTransportationImport(MultipartFile file, BusMaterialData param) {
        try {
            FileUtils.importExcel(
                    file,
                    AccTransportationImportModel.class,
                    new AccTransportationImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAccTransportation(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "运输费数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

//  public String accAluminumImport(MultipartFile file, BusMaterialData param) {
//    try {
//      FileUtils.importExcel(
//          file,
//              AccRawMatImportModel.class,
//          new AccRawMatImportListener(
//              param,
//              new ImportCallBack() {
//                @Override
//                public void onSuccess() {
//                  msg = "导入完成";
//                }
//                @Override
//                public void onWarning(List list) {
//                  msg = "部份数据无法导入，请点击下载检查数据内容";
//                  exportErrorExcelAccRawMat(list);
//                }
//              },
//              accountingInfoDao));
//      logService.saveLog("核算清单编辑", "原材料数据导入");
//    } catch (Exception e) {
//      e.printStackTrace();
//      return "导入失败";
//    }
//
//    return msg;
//  }

    /**
     * @methodName: laborTimeImport
     * @description: 导入人工工时
     * @param: file
     * @param: param
     * @return： java.lang.String
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/27 16:03
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public String laborTimeImport(MultipartFile file, BusBudgetAccountingCost param) {
        try {
            FileUtils.importExcel(
                    file,
                    LaborTimeModel.class,
                    new LaborImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelLaborTime(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑", "人工工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * purImport 导入外协件数据
     *
     * @param file  文件
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/11/21 14:44
     */
    public String whiOutImport(MultipartFile file, OutModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    OutModel.class,
                    new OutImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelWhiOut(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("核算清单编辑-外协件信息编辑", "外协件数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }

        return msg;
    }

    /**
     * cutHoursImport 下料工时导入
     *
     * @param file
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/26 13:10
     */
    public String cutHoursImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    CutImportModel.class,
                    new CutHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelCutHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-下料工时信息编辑", "下料工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * assemblyHoursImport 装配工时导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/30 18:36
     */
    public String assemblyHoursImport(MultipartFile file, AssemblyExportModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    AssemblyExportModel.class,
                    new AssemblyHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAssemblyHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-装配工时信息编辑", "装配工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * assemblyAuxImport 装配辅材导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/30 18:50
     */
    public String assemblyAuxImport(MultipartFile file, AssemblyExportModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    AssemblyAuxExportModel.class,
                    new AssemblyAuxImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAssemblyAux(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-装配工时信息编辑", "装配工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * rivetAndSolderHoursImport 导入铆焊工时数据
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/28 9:11
     */
    public String rivetAndSolderHoursImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    RivetAndSolderImportModel.class,
                    new RivetAndSolderHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelRivetAndSolderHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-铆焊工时信息编辑", "铆焊工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * rivetAndSolderAuxImport 导入铆焊辅材数据
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/28 9:11
     */
    public String rivetAndSolderAuxImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    RivetAndSolderAuxImportModel.class,
                    new RivetAndSolderAuxImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelRivetAndSolderAux(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-铆焊工时信息编辑", "铆焊工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * cutAuxImport 下料辅材导入
     *
     * @param file
     * @param param
     * @return void
     * @author 徐一贺
     * @date 2020/12/26 13:10
     */
    public String cutAuxImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    CutAuxImportModel.class,
                    new CutAuxImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelCutAux(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-下料工时信息编辑", "下料辅材数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * transportImport 运输费导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/5 20:36
     */
    public String transportImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    TransportExportModel.class,
                    new TransportImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelTransport(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-运输费信息编辑", "运输费数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * installHoursImport 安装工时导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/4 19:05
     */
    public String installHoursImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    InstallExportModel.class,
                    new InstallHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelInstallHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-安装工时信息编辑", "安装工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * debugHoursImport 调试工时导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/4 19:05
     */
    public String debugHoursImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    DebugExportModel.class,
                    new DebugHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelDebugHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-调试工时信息编辑", "调试工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * packingHoursImport 导入包装工时数据
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/5 18:25
     */
    public String packingHoursImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    PackingExportModel.class,
                    new PackingHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelPackingHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-包装工时信息编辑", "包装工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * packingAuxImport 包装辅材信息导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/5 18:50
     */
    public String packingAuxImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    PackingAuxExportModel.class,
                    new PackingAuxImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelPackingAux(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-包装辅材信息编辑", "包装辅材数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * designHoursImport 设计工时导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/5 10:46
     */
    public String designHoursImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    DesignExportModel.class,
                    new DesignHoursImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelDesignHours(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-调试工时信息编辑", "调试工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * designWeightImport 导入设计重量数据
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/5 11:12
     */
    public String designWeightImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    DesignWeightExportModel.class,
                    new DesignWeightImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelDesignWeight(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-调试工时信息编辑", "调试工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * auxImport 导入安装辅材数据
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2021/1/4 20:48
     */
    public String auxImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    AuxExportModel.class,
                    new AuxImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelAux(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-调试工时信息编辑", "调试工时数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * heatTreatmentImport 热处理导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/30 20:47
     */
    public String heatTreatmentImport(MultipartFile file, BusGeneralHoursModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    HeatTreatmentExportModel.class,
                    new HeatTreatmentImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelHeatTreatment(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-下料工时信息编辑", "下料辅材数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * sprayHoursImport 喷涂工时导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/30 14:31
     */
    public String sprayHoursImport(MultipartFile file, SprayExportModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    SprayExportModel.class,
                    new SprayImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelSpray(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-下料工时信息编辑", "下料辅材数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * sprayAuxImport 喷涂辅材导入
     *
     * @param file
     * @param param
     * @return java.lang.String
     * @author 徐一贺
     * @date 2020/12/30 14:49
     */
    public String sprayAuxImport(MultipartFile file, SprayExportModel param) {
        try {
            FileUtils.importExcel(
                    file,
                    SprayAuxExportModel.class,
                    new SprayAuxImportListener(
                            param,
                            new ImportCallBack() {
                                @Override
                                public void onSuccess() {
                                    msg = "导入完成";
                                }

                                @Override
                                public void onWarning(List list) {
                                    msg = "部份数据无法导入，请点击下载检查数据内容";
                                    exportErrorExcelSprayAux(list);
                                }
                            },
                            accountingInfoDao));
            logService.saveLog("概算算清单调整-下料工时信息编辑", "下料辅材数据导入");
        } catch (Exception e) {
            e.printStackTrace();
            return "导入失败";
        }
        return msg;
    }

    /**
     * 原材料异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcel(List<RawMatModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorMat.xlsx", RawMatModel.class, "未成功导入数据", errorList);
    }

    /**
     * 外购费异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelPurEst(List<PurExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorPur.xlsx", PurExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 原材料铝材异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorAluExcel(List<AluminiumExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorMat.xlsx", AluminiumExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 铝材异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelAlum(List<AluminiumModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorAou.xlsx", AluminiumModel.class, "未成功导入数据", errorList);
    }

    /**
     * 机加异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelMac(List<MacHoursExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorMacHours.xlsx", MacHoursExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 外购件异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelPur(List<PurModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorPur.xlsx", PurModel.class, "未成功导入数据", errorList);
    }

    /**
     * 整体外协异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelWhole(List<WholeExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorWhole.xlsx", WholeExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * exportErrorExcelWithMat 带料外协异常数据导出到Excel
     *
     * @param errorList
     * @return void
     * @author 徐一贺
     * @date 2021/1/4 14:41
     */
    private void exportErrorExcelWithMat(List<WithMatExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorWithMat.xlsx", WithMatExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 备品备件异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelSparePart(List<SparePartsModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorSp.xlsx", PurModel.class, "未成功导入数据", errorList);
    }

    /**
     * 备品备件异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelAccompanyingSparePart(List<SparePartsModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorAsp.xlsx", SparePartsModel.class, "未成功导入数据", errorList);
    }

    /**
     * 外协件异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelOut(List<OutModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorWho.xlsx", OutModel.class, "未成功导入数据", errorList);
    }

    /**
     * 设计重量异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelWeight(List<DesignWeightModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorWeight.xlsx", DesignWeightModel.class, "未成功导入数据", errorList);
    }

    /**
     * 人工工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelLaborTime(List<LaborTimeModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorLaborTime.xlsx", LaborTimeModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccPur
     * @description: 导出错误
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 16:52
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccPur(List<AccPurImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorPur.xlsx", AccPurImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccRawMat
     * @description: 导入原材料错误导出
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 19:53
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccRawMat(List<AccRawMatImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorRawMat.xlsx", AccRawMatImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccOut
     * @description: 导入外协件错误文件导出
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 20:49
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccOut(List<AccOutImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorOut.xlsx", AccOutImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccAluminum
     * @description: 导出错误铝材数据
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 16:01
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccAluminum(List<AccAluminiumMatImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorAluminum.xlsx", AccAluminiumMatImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccOtherHours
     * @description: 导入其他工时错误文件导出
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 8:57
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccOtherHours(List<AccOtherHoursImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorOther.xlsx", AccOtherHoursImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccOtherAux
     * @description: 导入其他辅材错误文件导出
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 11:51
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccOtherAux(List<AccOtherAuxImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorOtherAux.xlsx", AccOtherAuxImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccHeatTreatment
     * @description: 核算热处理错误数据导出
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 13:16
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccHeatTreatment(List<AccHeatTreatmentImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorHeatTreat.xlsx", AccHeatTreatmentImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccTransportation
     * @description: 运输费数据导入
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 13:47
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccTransportation(List<AccTransportationImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorTransportation.xlsx", AccTransportationImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * @methodName: exportErrorExcelAccMachiningHours
     * @description: 机加工时错误数据导出
     * @param: errorList
     * @return： void
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 15:07
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    private void exportErrorExcelAccMachiningHours(List<AccMachiningHoursImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "accErrorMachiningHours.xlsx", AccMachiningHoursImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 外协件异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelWhiOut(List<OutModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorWhi.xlsx", OutModel.class, "未成功导入数据", errorList);
    }

    /**
     * 下料工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelCutHours(List<CutImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorCutHours.xlsx", CutImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 装配工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelAssemblyHours(List<AssemblyExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path, "errorAssemblyHours.xlsx", AssemblyExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 装配辅材异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelAssemblyAux(List<AssemblyAuxExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path, "erroAssemblyAux.xlsx", AssemblyAuxExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * exportErrorExcelRivetAndSolderHours 号码工时错误数据导出
     *
     * @param errorList
     * @return void
     * @author 徐一贺
     * @date 2020/12/28 9:13
     */
    private void exportErrorExcelRivetAndSolderHours(List<RivetAndSolderImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path,
                "errorRivetAndSolderHours.xlsx",
                RivetAndSolderImportModel.class,
                "未成功导入数据",
                errorList);
    }

    /**
     * exportErrorExcelRivetAndSolderAux 铆焊辅材错误数据导出
     *
     * @param errorList
     * @return void
     * @author 徐一贺
     * @date 2020/12/28 9:13
     */
    private void exportErrorExcelRivetAndSolderAux(List<RivetAndSolderAuxImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path,
                "errorRivetAndSolderAus.xlsx",
                RivetAndSolderAuxImportModel.class,
                "未成功导入数据",
                errorList);
    }

    /**
     * 下料辅材异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelCutAux(List<CutAuxImportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorCutAux.xlsx", CutAuxImportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 运输费异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelTransport(List<TransportExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path, "errorTransport.xlsx", TransportExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 热处理异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelHeatTreatment(List<HeatTreatmentExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path, "errorheatTreatment.xlsx", HeatTreatmentExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 安装工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelInstallHours(List<InstallExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorInstall.xlsx", InstallExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 调试工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelDebugHours(List<DebugExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorDebug.xlsx", DebugExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 包装工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelPackingHours(List<PackingExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path, "errorPackingHours.xlsx", PackingExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 包装辅材异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelPackingAux(List<PackingAuxExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path, "errorPackingAux.xlsx", PackingAuxExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 设计工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelDesignHours(List<DesignExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path, "errorDesignHours.xlsx", DesignExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 设计工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelDesignWeight(List<DesignWeightExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(
                path, "errorDesignWeight.xlsx", DesignWeightExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 安装辅材异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelAux(List<AuxExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorAux.xlsx", AuxExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 喷涂工时异常数据导出到Excel
     *
     * @param errorList
     */
    private void exportErrorExcelSpray(List<SprayExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "errorSprayHours.xlsx", SprayExportModel.class, "未成功导入数据", errorList);
    }

    private void exportErrorExcelSprayAux(List<SprayAuxExportModel> errorList) {
        if (errorList.size() <= 0) {
            return;
        }
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.genExcel(path, "erroSprayAux.xlsx", SprayAuxExportModel.class, "未成功导入数据", errorList);
    }

    /**
     * 错误文件导出
     *
     * @param url 文件URL
     * @return 是否存在
     */
    public boolean exist(String url) {
        int i = url.lastIndexOf("files/");
        String path = uploadPath + url.substring(i + 6);
        File file = new File(path);
        if (!file.exists()) {
            return false;
        }
        return true;
    }

    /**
     * switchAmountModel 切换金额显示模式
     *
     * @param param 参数
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/3 12:52
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult switchAmountModel(BusBudgetAccountingCostModel param) {
        JsonResult result = new JsonResult();
        try {
            List<BusBudgetAccountingCost> costList =
                    accountingInfoDao.findBusBudgetAccountingCostByBatId(param.getBatId());
            for (int i = 0; i < costList.size(); i++) {
                BusBudgetAccountingCost costModel = costList.get(i);
                if (param.getAmountDisplayModel().intValue() == 1) {
                    if (costModel.getPrice() != null) {
                        costModel.setDisplayPrice(
                                costModel
                                        .getPrice()
                                        .divide(new BigDecimal(1), 0, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    if (costModel.getTotalPrice() != null) {
                        costModel.setDisplayTotalPrice(
                                costModel
                                        .getTotalPrice()
                                        .divide(new BigDecimal(1), 0, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    if (costModel.getTrueAmount() != null) {
                        costModel.setDisplayTrueAmount(
                                costModel
                                        .getTrueAmount()
                                        .divide(new BigDecimal(1), 0, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                }
                if (param.getAmountDisplayModel().intValue() == 2) {
                    if (costModel.getPrice() != null) {
                        costModel.setDisplayPrice(
                                costModel
                                        .getPrice()
                                        .divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    if (costModel.getTotalPrice() != null) {
                        costModel.setDisplayTotalPrice(
                                costModel
                                        .getTotalPrice()
                                        .divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    if (costModel.getTrueAmount() != null) {
                        costModel.setDisplayTrueAmount(
                                costModel
                                        .getTrueAmount()
                                        .divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                }
                if (param.getAmountDisplayModel().intValue() == 3) {
                    if (costModel.getPrice() != null) {
                        costModel.setDisplayPrice(
                                costModel
                                        .getPrice()
                                        .divide(new BigDecimal(1000000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    if (costModel.getTotalPrice() != null) {
                        costModel.setDisplayTotalPrice(
                                costModel
                                        .getTotalPrice()
                                        .divide(new BigDecimal(1000000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    if (costModel.getTrueAmount() != null) {
                        costModel.setDisplayTrueAmount(
                                costModel
                                        .getTrueAmount()
                                        .divide(new BigDecimal(1000000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                }
                if (param.getAmountDisplayModel().intValue() == 4) {
                    if (costModel.getPrice() != null) {
                        costModel.setDisplayPrice(
                                costModel
                                        .getPrice()
                                        .divide(new BigDecimal(100000000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    if (costModel.getTotalPrice() != null) {
                        costModel.setDisplayTotalPrice(
                                costModel
                                        .getTotalPrice()
                                        .divide(new BigDecimal(100000000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }

                    if (costModel.getTrueAmount() != null) {
                        costModel.setDisplayTrueAmount(
                                costModel
                                        .getTrueAmount()
                                        .divide(new BigDecimal(100000000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                }
                costModel.setAmountDisplayModel(param.getAmountDisplayModel());
                accountingInfoDao.updateBusBudgetAccountingCostByPrimaryKeySelective(costModel);
                result.setType(JsonResult.ResultType.SUCCESS);
                result.setMsg("切换成功！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            result.setType(JsonResult.ResultType.ERROR);
            result.setMsg("切换失败！");
        }
        return result;
    }

    /**
     * loadControlDropDownMenuDisplayParameters 根据单据表ID获取成本项金额显示模式
     *
     * @param batId 单据表主键
     * @return java.lang.Integer 显示模式
     * @author 徐一贺
     * @date 2020/12/7 16:29
     */
    public Integer loadControlDropDownMenuDisplayParameters(Integer batId) {
        return accountingInfoDao
                .findBusBudgetAccountingCostByBatId(batId)
                .get(0)
                .getAmountDisplayModel();
    }

    /**
     * loadWeightParams 根据单据表Id获取重量参数
     *
     * @param batId
     * @return com.zhongwang.business.module.estimateBudgetAccountingManage.model.WeightParamModel
     * @author 徐一贺
     * @date 2020/12/7 16:35
     */
    public WeightParamModel loadWeightParams(Integer batId) {
        WeightParamModel resultParam = new WeightParamModel();
        BigDecimal equipmentTotalWeight =
                getDataService.getAccountingEquipmentTotalWeightByBatId(batId);
        BigDecimal equipmentTotalNetWeight =
                getDataService.getAccountingEquipmentTotalNetWeightByBatId(batId);
        resultParam.setWeight(equipmentTotalWeight);
        resultParam.setNetWeight(equipmentTotalNetWeight);
        return resultParam;
    }

    /**
     * loadConfigParams 根据单据表主键获取需要的核算参数
     *
     * @param batId 单据表主键
     * @return java.util.List
     * @author 徐一贺
     * @date 2020/12/7 16:48
     */
    public List<BusBudgetAccountingBasicInfoConfig> loadConfigParams(Integer batId) {
        return getDataService.findBusBudgetAccountingBasicInfoConfigByBatId(batId);
    }

    /**
     * loadCostSheet 根据单据表主键加载核算成本清单
     *
     * @param batId 单据表主键
     * @return java.util.List
     * @author 徐一贺
     * @date 2020/12/7 17:09
     */
    public List<BusBudgetAccountingCostModel> loadCostSheet(Integer batId) {
        return getDataService.findBusBudgetAccountingCostListByBatId(batId.toString(), 5);
    }

    /**
     * loadMainParam 根据单据表主键加载主要参数
     *
     * @param batId 单据表ID
     * @return java.lang.String 主要参数
     * @author 徐一贺
     * @date 2020/12/10 10:18
     */
    public String loadMainParam(Integer batId) {
        return accountingInfoDao.loadMainParam(batId);
    }

    /**
     * loadNote 加载note
     *
     * @param batId 单据表ID
     * @return java.lang.Object
     * @author 徐一贺
     * @date 2020/12/10 10:41
     */
    public BusBudgetAccountingTaskModel loadNote(Integer batId) {
        return accountingInfoDao.loadNote(batId);
    }

    /**
     * toChange 根据单据表主键更改单据表对应的值
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @throws
     * @author 徐一贺
     * @date 2020/12/10 13:30
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult toChange(BusBudgetAccountingTaskModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            switch (param.getField()) {
                case "priceRangeDesignFlag":
                    param.setField("price_range_design_flag");
                    break;
                case "priceRangeMateriaFlag":
                    param.setField("price_range_materia_flag");
                    break;
                case "priceRangeManufactureFlag":
                    param.setField("price_range_manufacture_flag");
                    break;
                case "priceRangePackingFlag":
                    param.setField("price_range_packing_flag");
                    break;
                case "priceRangeTransportFlag":
                    param.setField("price_range_transport_flag");
                    break;
                case "priceRangeInstallBusinessTravelSubsidyFlag":
                    param.setField("price_range_install_business_travel_subsidy_flag");
                    break;
                case "priceRangeInstallAccommodationFlag":
                    param.setField("price_range_install_accommodation_flag");
                    break;
                case "priceRangeInstallBusinessTravelFlag":
                    param.setField("price_range_install_business_travel_flag");
                    break;
                case "priceRangeInstallHoistingFlag":
                    param.setField("price_range_install_hoisting_flag");
                    break;
                case "priceRangeDebugFlag":
                    param.setField("price_range_debug_flag");
                    break;
                case "priceRangeSparePartsFlag":
                    param.setField("price_range_spare_parts_flag");
                    break;
                case "priceRangeTransportGuaranteeFlag":
                    param.setField("price_range_transport_guarantee_flag");
                    break;
                case "priceRangeInstall":
                    param.setField("price_range_install");
                    break;
            }
            accountingInfoDao.updateBusBudgetAccountingTaskByPrimaryAndSelectiveColumn(param);
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
        }
        return jsonResult;
    }

    /**
     * saveHeatTreatmentEdit 保存热处理编辑
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2020/12/30 20:10
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult saveHeatTreatmentEdit(BusGeneralHoursModel param) {
        JsonResult jsonResult = new JsonResult();
        try {
            accountingInfoDao.updateBusGeneralHoursModelByPrimaryKeySelective(param);
            logService.saveLog("概算清单调整-制造费明细-制造费热处理编辑", "保存编辑，热处理形式为：【" + param.getLaborName() + "】");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("保存成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
        }
        return jsonResult;
    }

    /**
     * addCostItem 添加成本项
     *
     * @param param
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/6 12:47
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult addCostItem(BusBudgetAccountingCost param) {
        JsonResult jsonResult = new JsonResult();
        try {
            param.setName(XYHFileUtils.replaceBlank(param.getName()));
            // 检测该成本项是否存在
            BusBudgetAccountingCost addCostItem =
                    accountingInfoDao.getBusBudgetAccountingCostByParam(param);
            // 获取父级成本项
            BusBudgetAccountingCost parentCostItem = accountingInfoDao.getParentCostItemByParam(param);
            if (addCostItem == null) {
                // 获取全部成本项并按照orderNo排序
                List<BusBudgetAccountingCost> costItems =
                        accountingInfoDao.findBusBudgetAccountingCostByBatId(param.getBatId());
                List<BusBudgetAccountingCost> childCostItems = new ArrayList<>();
                // 获取父级下所有子集的集合
                for (int i = 0; i < costItems.size(); i++) {
                    BusBudgetAccountingCost currentItem = costItems.get(i);
                    if (currentItem.getParentCode().equals(param.getParentCode())) {
                        childCostItems.add(currentItem);
                    }
                }
                if (childCostItems.size() > 0) {
                    // 获取兄弟级的最终子孙级的最后排序
                    param.setOrderNo(childCostItems.get(childCostItems.size() - 1).getOrderNo() + 1);
                } else {
                    param.setOrderNo(parentCostItem.getOrderNo() + 1);
                }
                if (parentCostItem != null) {
                    param.setMajor(parentCostItem.getMajor());
                    param.setPart(parentCostItem.getPart());
                    param.setItemType(parentCostItem.getItemType());
                    param.setAmountDisplayModel(parentCostItem.getAmountDisplayModel());
                    if (!param.getParentCode().equals("合计") && !param.getParentCode().equals("总计")) {
                        param.setCode(param.getParentCode() + "-" + param.getName());
                        param.setRank(parentCostItem.getRank() + 1);
                    } else {
                        param.setCode(param.getName());
                        param.setRank(1);
                    }
                }
                param.setFinishStatus(3);
                param.setCreateTime(new Date());
                param.setDataSource("0");
                param.setTextureEditFlag(0);
                param.setRemarkEditFlag(1);
                param.setPriceEditFlag(0);
                param.setTotalPriceFlag(1);
                param.setNumEditFlag(0);
                param.setViewInfoFlag(0);
                param.setDeleteFlag(0);
                param.setDisplayFlag(1);
                param.setIsMajor(0);
                param.setIsPart(0);
                param.setIsInvalid(0);
                param.setShowFinishStatus(0);
                param.setShowDataSource(0);
                param.setIsEffectiveFlag(1);
                if (parentCostItem.getAmountDisplayModel() == 1) {
                    param.setDisplayTrueAmount(
                            param.getTrueAmount().setScale(0, BigDecimal.ROUND_HALF_UP).toString());
                } else if (parentCostItem.getAmountDisplayModel() == 2) {
                    param.setDisplayTrueAmount(
                            param
                                    .getTrueAmount()
                                    .divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP)
                                    .toString());
                }
                getDataDao.insertBusBudgetAccountingCost(param);
                for (int i = 0; i < costItems.size(); i++) {
                    BusBudgetAccountingCost currentItem = costItems.get(i);
                    if (currentItem.getOrderNo().intValue() >= param.getOrderNo().intValue()) {
                        currentItem.setOrderNo(currentItem.getOrderNo() + 1);
                        getDataDao.updateBusBudgetAccountingCostOrderNoByPrimaryKey(currentItem);
                    }
                }
                if (parentCostItem
                        .getCode()
                        .substring(parentCostItem.getCode().lastIndexOf("-"))
                        .equals("-材料采购费")) {
                    BusBudgetAccountingCost wasteCondition = new BusBudgetAccountingCost();
                    wasteCondition.setBatId(parentCostItem.getBatId());
                    wasteCondition.setCode(parentCostItem.getCode().replace("材料采购费", "废料回收费"));
                    // 获取对应的废料回收废
                    BusBudgetAccountingCost wasteCost = getDataDao.getWasteCostByParam(wasteCondition);
                    param.setParentCode(wasteCost.getCode());
                    childCostItems = new ArrayList<>();
                    // 获取父级下所有子集的集合
                    for (int i = 0; i < costItems.size(); i++) {
                        BusBudgetAccountingCost currentItem = costItems.get(i);
                        if (currentItem.getParentCode().equals(wasteCost.getCode())) {
                            childCostItems.add(currentItem);
                        }
                    }
                    if (childCostItems.size() > 0) {
                        param.setOrderNo(lastChildOrderNo(childCostItems.get(childCostItems.size() - 1)) + 1);
                    } else {
                        param.setOrderNo(wasteCost.getOrderNo() + 1);
                    }
                    if (wasteCost != null) {
                        param.setMajor(wasteCost.getMajor());
                        param.setPart(wasteCost.getPart());
                        param.setItemType(wasteCost.getItemType());
                        param.setAmountDisplayModel(wasteCost.getAmountDisplayModel());
                        if (!param.getParentCode().equals("合计") && !param.getParentCode().equals("总计")) {
                            param.setCode(param.getParentCode() + "-" + param.getName());
                            param.setRank(wasteCost.getRank() + 1);
                        } else {
                            param.setCode(param.getName());
                            param.setRank(1);
                        }
                    }
                    param.setFinishStatus(3);
                    param.setCreateTime(new Date());
                    param.setDataSource("0");
                    param.setTextureEditFlag(0);
                    param.setRemarkEditFlag(1);
                    param.setPriceEditFlag(0);
                    param.setTotalPriceFlag(1);
                    param.setNumEditFlag(0);
                    param.setViewInfoFlag(0);
                    param.setDeleteFlag(0);
                    param.setDisplayFlag(1);
                    param.setIsMajor(0);
                    param.setIsPart(0);
                    param.setIsInvalid(0);
                    param.setShowFinishStatus(0);
                    param.setShowDataSource(0);
                    param.setIsEffectiveFlag(1);
                    if (parentCostItem.getAmountDisplayModel() == 1) {
                        param.setDisplayTrueAmount(
                                param.getTrueAmount().setScale(0, BigDecimal.ROUND_HALF_UP).toString());
                    } else if (parentCostItem.getAmountDisplayModel() == 2) {
                        param.setDisplayTrueAmount(
                                param
                                        .getTrueAmount()
                                        .divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP)
                                        .toString());
                    }
                    getDataDao.insertBusBudgetAccountingCost(param);
                    for (int i = 0; i < costItems.size(); i++) {
                        BusBudgetAccountingCost currentItem = costItems.get(i);
                        if (currentItem.getOrderNo().intValue() >= param.getOrderNo().intValue()) {
                            currentItem.setOrderNo(currentItem.getOrderNo() + 1);
                            getDataDao.updateBusBudgetAccountingCostOrderNoByPrimaryKey(currentItem);
                        }
                    }
                }
                logService.saveLog("概算清单调整", "新增成本项：【" + param.getName() + "】");
                jsonResult.setType(JsonResult.ResultType.SUCCESS);
                jsonResult.setMsg("保存成功！");
            } else {
                jsonResult.setType(JsonResult.ResultType.ERROR);
                jsonResult.setMsg("该成本项已存在请重新命名！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("保存失败！");
        }
        return jsonResult;
    }

    /**
     * lastChildOrderNo 获取最终的排序序号
     *
     * @param param
     * @return java.lang.Integer
     * @author 徐一贺
     * @date 2021/1/7 16:22
     */
    private Integer lastChildOrderNo(BusBudgetAccountingCost param) {
        return findLastChildCostItem(param).getOrderNo();
    }

    /**
     * findLastChildCostItem 递归寻找最后项的子孙项
     *
     * @param param
     * @return com.zhongwang.business.gen.entity.BusBudgetAccountingCost
     * @author 徐一贺
     * @date 2021/1/7 16:20
     */
    private BusBudgetAccountingCost findLastChildCostItem(BusBudgetAccountingCost param) {
        List<BusBudgetAccountingCost> childCostItems =
                getDataDao.findBusBudgetAccountingCostByParentCodeAndBatIdOrderByOrderNo(param);
        if (childCostItems.size() == 0) {
            return param;
        } else {
            return findLastChildCostItem(childCostItems.get(childCostItems.size() - 1));
        }
    }

    /**
     * deleteCostItem 删除成本项
     *
     * @param id
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/7 9:38
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult deleteCostItem(Integer id) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingCost cost = accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(id);
            cost.setIsEffectiveFlag(0);
            accountingInfoDao.updateBusBudgetAccountingCostByPrimaryKey(cost);
            logService.saveLog("概算清单调整", "删除成本项：【" + cost.getName() + "】");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("删除成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("删除失败！");
        }
        return jsonResult;
    }

    /**
     * recovery 恢复成本项
     *
     * @param id
     * @return com.zhongwang.business.common.JsonResult
     * @author 徐一贺
     * @date 2021/1/7 14:15
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult recovery(Integer id) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingCost cost = accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(id);
            cost.setIsEffectiveFlag(1);
            accountingInfoDao.updateBusBudgetAccountingCostByPrimaryKey(cost);
            logService.saveLog("概算清单调整", "恢复成本项：【" + cost.getName() + "】");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("恢复成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("恢复失败！");
        }
        return jsonResult;
    }

    /**
     * @methodName: getPartList
     * @description: 根据成本项总单和专业获取部分列表
     * @param: param
     * @return： com.zhongwang.business.common.JsonResult
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/27 10:32
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public List<String> getPartList(BusBudgetAccountingCost param) {
        return accountingInfoDao.findPartListByBatIdAndMajor(param);
    }

    /**
     * @methodName: loadDesignWeightList
     * @description: 加载导入后的设备重量列表
     * @param: designWeightModel
     * @return： java.util.List<com.zhongwang.business.module.estimateBudgetAccountingManage.model.excelImport.DesignWeightModel>
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 14:21
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public List<DesignWeightModel> loadDesignWeightList(DesignWeightModel designWeightModel) {
        BusGeneralHours param = new BusGeneralHours();
        BeanUtil.copy(designWeightModel, param);
        List<BusGeneralHours> busGeneralHoursList = accountingInfoDao.findBusGeneralHoursByParam(param);
        List<DesignWeightModel> resultList = new ArrayList<>();
        for (int i = 0; i < busGeneralHoursList.size(); i++) {
            DesignWeightModel obj = new DesignWeightModel();
            BeanUtil.copy(busGeneralHoursList.get(i), obj);
            resultList.add(obj);
        }
        return resultList;
    }

    /**
     * @methodName: removeEquipmentWeightData
     * @description: 删除重量数据
     * @param: id
     * @return： com.zhongwang.business.common.JsonResult
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 15:16
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult removeEquipmentWeightData(Integer id) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusGeneralHours hours = accountingInfoDao.getBusGeneralHoursByPrimary(id);
            Integer busMaterialDataCount = accountingInfoDao.getBusGeneralHoursCountByConstId(hours.getCostId());
            if (busMaterialDataCount == 0) {
                BusBudgetAccountingCost cost = new BusBudgetAccountingCost();
                cost.setId(hours.getCostId());
                cost.setDataSource("0");
                accountingInfoDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
            }
            accountingInfoDao.deleteBusGeneralHoursByPrimary(id);
            logService.saveLog("删除重量数据", "项目号为：【" + hours.getProCode() + "】。名称为：【" + hours.getLaborName() + "】的数据被删除了！");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("删除重量数据成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除重量数据异常" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("删除重量数据失败！");
        }
        return jsonResult;
    }

    /**
     * @methodName: findBusMaterialDataByParam
     * @description: 根据参数查询外购件列表
     * @param: param
     * @return： java.util.List<com.zhongwang.business.gen.entity.BusMaterialData>
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 16:17
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public List<BusMaterialData> findBusMaterialDataByParam(BusMaterialData param) {
        return accountingInfoDao.findBusMaterialDataByParam(param);
    }

    /**
     * @methodName: removeBusMaterialDataByPrimaryKey
     * @description: 根据主键删除材料表数据
     * @param: valueOf
     * @return： com.zhongwang.business.gen.entity.BusBudgetAccountingAlgorithm
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/29 18:20
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult removeBusMaterialDataByPrimaryKey(Integer primaryKey) {
        JsonResult jsonResult = new JsonResult();
        try {
            String type = "";
            String texture = "";
            BusMaterialData busMaterialData = accountingInfoDao.getBusMaterialDataByPrimary(primaryKey);
            Integer busMaterialDataCount = accountingInfoDao.getBusMaterialDataByConstId(busMaterialData.getCostId());
            if (busMaterialDataCount == 0) {
                BusBudgetAccountingCost cost = new BusBudgetAccountingCost();
                cost.setId(busMaterialData.getCostId());
                cost.setDataSource("0");
                accountingInfoDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
            }
            if (busMaterialData.getDataType().intValue() == 1) {
                type = "原材料";
                texture = "，材质为【" + busMaterialData.getTexture() + "】";
            } else if (busMaterialData.getDataType().intValue() == 2) {
                type = "外购件";
            } else if (busMaterialData.getDataType().intValue() == 3) {
                type = "整体外协";
            } else if (busMaterialData.getDataType().intValue() == 4) {
                type = "带料外协";
            } else if (busMaterialData.getDataType().intValue() == 5) {
                type = "锻件毛坯";
            } else if (busMaterialData.getDataType().intValue() == 6) {
                type = "铸件毛坯";
            }
            accountingInfoDao.deleteBusMaterialDataByPrimary(primaryKey);
            logService.saveLog("删除数据", "项目号为：【" + busMaterialData.getProCode() + "】。物料描述为：【" + busMaterialData.getMatDesc() + "】的【" + type + "】" + texture + "数据被删除了！");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("删除重量数据成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除重量数据异常" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("删除重量数据失败！");
        }
        return jsonResult;
    }

    /**
     * @methodName: loadBusGeneralHoursList
     * @description: 获取其他工时列表
     * @param: param
     * @return： java.util.List<com.zhongwang.business.gen.entity.BusGeneralHours>
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 8:45
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public List<BusGeneralHours> loadBusGeneralHoursList(BusGeneralHours param) {
        return accountingInfoDao.findBusGeneralHoursByParam(param);
    }

    /**
     * @methodName: loadBusMachiningHoursList
     * @description: 核算导入机加工时加载列表
     * @param: param
     * @return： java.util.List<com.zhongwang.business.gen.entity.BusGeneralHours>
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 14:41
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public List<BusMachiningHours> loadBusMachiningHoursList(BusMachiningHours param) {
        return accountingInfoDao.loadBusMachiningHoursList(param);
    }

    /**
     * @methodName: removeBusGeneralHoursByPrimaryKey
     * @description: 根据主键们删除公式、辅材、重量、运输、热处理表数据
     * @param: valueOf
     * @return： com.zhongwang.business.gen.entity.BusBudgetAccountingAlgorithm
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 9:49
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult removeBusGeneralHoursByPrimaryKey(Integer primaryKey) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusGeneralHours busGeneralHours = accountingInfoDao.getBusGeneralHoursByPrimary(primaryKey);
            Integer busMaterialDataCount = accountingInfoDao.getBusGeneralHoursCountByConstId(busGeneralHours.getCostId());
            if (busMaterialDataCount == 0) {
                BusBudgetAccountingCost cost = new BusBudgetAccountingCost();
                cost.setId(busGeneralHours.getCostId());
                cost.setDataSource("0");
                accountingInfoDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
            }
            accountingInfoDao.deleteBusGeneralHoursByPrimary(primaryKey);
            if(busGeneralHours.getLaborType().intValue()!= 17){
                logService.saveLog("其他人工工时/辅材/重量/热处理/机加工时/运输服导入-删除数据", "项目号为：【" + busGeneralHours.getProCode() + "】。类别为：【" + busGeneralHours.getLaborName() + "】的数据！");
            }else{
                logService.saveLog("运输费导入-删除数据", "项目号为：【" + busGeneralHours.getProCode() + "】。发货地：【" + busGeneralHours.getPlaceDelivery() + "】，目的地【"+busGeneralHours.getDestination()+"】的运输数据！");
            }
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("删除成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据主键们删除公式、辅材、重量、运输、热处理表数据异常" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("删除失败！");
        }
        return jsonResult;
    }

    /**
     * @methodName: removeBusMachiningHoursByIds
     * @description: 根据主键删除机加工时
     * @param: id
     * @return： com.zhongwang.business.common.JsonResult
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 15:26
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult removeBusMachiningHoursByIds(Integer id) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusMachiningHours busMachiningHours = accountingInfoDao.getBusMachiningHoursByPrimary(id);
            Integer busMaterialDataCount = accountingInfoDao.getBusMachiningHoursCountByConstId(busMachiningHours.getCostId());
            if (busMaterialDataCount == 0) {
                BusBudgetAccountingCost cost = new BusBudgetAccountingCost();
                cost.setId(busMachiningHours.getCostId());
                cost.setDataSource("0");
                accountingInfoDao.updateBusBudgetAccountingCostDataSourceByPrimaryKey(cost);
            }
            accountingInfoDao.deleteBusMachiningHoursByPrimary(id);
            logService.saveLog("机加工时导入-删除数据", "项目号为【" + busMachiningHours.getProCode() + "】，图号为【" + busMachiningHours.getDiagram() + "】，工序为【" + busMachiningHours.getProcess() + "】，设备型号为【" + busMachiningHours.getBmeCode() + "】的机加工时数据被删除了！");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("删除成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据主键删除机加工时表数据异常" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("删除失败！");
        }
        return jsonResult;
    }
    /**
     * @methodName: getTotalPriceHaveTaxFromBusMaterialDataByCostId
     * @description: 根据成本项主键获取对应材料表的总价
     * @param: costId
     * @return： java.math.BigDecimal
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 18:09
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    public BigDecimal getTotalPriceHaveTaxFromBusMaterialDataByCostId(Integer costId) {
        return accountingInfoDao.getTotalPriceHaveTaxFromBusMaterialDataByCostId(costId);
    }

    /**
     * @methodName: saveUnforeseenPrice
     * @description: 保存不可预见费用
     * @param: cost
     * @return： com.zhongwang.business.common.JsonResult
     * @exception：
     * @author： 徐一贺 tel:18941916590
     * @designer： 陈欣，孔祥鑫
     * @leader： 陈欣 tel:18104194240
     * @date： 2021/3/30 19:26
     * @office: 智能控制设计科
     * @research institute： 智能控制设计所
     * @department： 机械设计院
     * @company: 辽宁忠旺机械设备制造有限公司
     * @group： 忠旺集团
     * @version: 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult saveUnforeseenPrice(BusBudgetAccountingCost cost) {
        JsonResult jsonResult = new JsonResult();
        try {
            BusBudgetAccountingCost busBudgetAccountingCost = accountingInfoDao.getBusBudgetAccountingCostByPrimaryKey(cost.getId());
            BusBudgetAccountingTask order = accountingInfoDao.getAbBudgetAccountingTaskByPrimaryKey(busBudgetAccountingCost.getBatId());
            accountingInfoDao.updateBusBudgetAccountingCostUnforeseenPriceByPrimaryKey(cost);
            logService.saveLog("不可预见计划列表-保存不可预见费用", "项目号为【" + order.getProCode() + "】，的不可预见费用被修改了，不可预见人工费修改前是【"+busBudgetAccountingCost.getUnforeseenArtificial()==null?"":busBudgetAccountingCost.getUnforeseenArtificial()+"】修改后是【"+cost.getUnforeseenArtificial()==null?"":cost.getUnforeseenArtificial()+"】,不可预见的其他费用修改前是【"+busBudgetAccountingCost.getUnforeseenOther()==null?"":busBudgetAccountingCost.getUnforeseenOther()+"】修改后是【"+cost.getUnforeseenOther()==null?"":cost.getUnforeseenOther()+"】。");
            jsonResult.setType(JsonResult.ResultType.SUCCESS);
            jsonResult.setMsg("删除成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据主键删除机加工时表数据异常" + e.getMessage());
            jsonResult.setType(JsonResult.ResultType.ERROR);
            jsonResult.setMsg("删除失败！");
        }
        return jsonResult;
    }
}
